# !/usr/bin python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import time, datetime
import json
import re
for line in sys.stdin:
try:
json_2 = json.loads(line, encoding='utf8')
for k,v in json_2.items():
if k == 'feed_list':
for i in range(len(v)):
nid =-1
q_ratio = -1
rec_src = -1
vt_ctr_fea =-1
predictor_q_score = -1
keys=v[i].keys()
ext=None
ext_keys=None
if 'ext' in keys:
ext= v[i].get('ext')
ext_keys=ext.keys()
if ext ==None:continue
if 'q_ratio' in ext_keys:
q_ratio= ext.get('q_ratio')
if 'rec_src' in ext_keys:
rec_src=ext.get('rec_src')[0]
#if rec_src not in xinmi:continue
if 'vt_ctr_fea' in ext_keys:
vt_ctr_fea= ext.get('vt_ctr_fea')
if 'predictor_q_score' in ext_keys:
predictor_q_score = ext.get('predictor_q_score')
if 'aq_value' in ext_keys:
aq_value = ext.get('aq_value')
print(cuid, nid, rec_src, predictor_q_score, vt_ctr_fea, q_ratio, aq_value,sep='\t')
except Exception as e:
pass
Python 解析嵌套json
最新推荐文章于 2023-10-06 12:53:20 发布