def addto_warning_corpus(task_detail): flow_text_index_name = flow_text_index_name_pre + ts2datetime(task_detail['timestamp']) try: corpus_result = es_flow_text.get(index=flow_text_index_name,doc_type=flow_text_index_type,id=task_detail['mid'])['_source'] corpus_result['xnr_user_no'] = task_detail['xnr_user_no'] corpus_result['warning_source'] = task_detail['warning_source'] corpus_result['create_time'] = task_detail['create_time'] corpus_result['validity'] = 1 corpus_result['nick_name'] = get_user_nickname(task_detail['uid']) #查询关注列表 lookup_type = 'followers_list' followers_list = lookup_xnr_fans_followers(task_detail['xnr_user_no'],lookup_type) set_mark = set_intersection(task_detail['uid'],followers_list) if set_mark > 0: corpus_result['content_type']='follow' else: corpus_result['content_type']='unfollow' es_xnr.index(index=weibo_warning_corpus_index_name,doc_type=weibo_warning_corpus_index_type,id=task_detail['mid'],body=corpus_result) mark=True except: mark=False return mark
def new_addto_weibo_corpus(task_detail): flow_text_index_name = flow_text_index_name_pre + ts2datetime(task_detail['timestamp']) try: corpus_result = es_flow_text.get(index=flow_text_index_name,doc_type=flow_text_index_type,id=task_detail['mid'])['_source'] task_detail['text']=corpus_result['text'] task_detail['retweeted']=corpus_result['retweeted'] task_detail['comment']=corpus_result['comment'] task_detail['like']=corpus_result['like'] except: mark=False try: es_xnr.index(index=weibo_xnr_corpus_index_name,doc_type=weibo_xnr_corpus_index_type,id=task_detail['mid'],body=task_detail) mark=True except: mark=False return mark
def report_warming_content(task_detail): report_dict=dict() report_dict['report_type']=task_detail['report_type'] report_dict['report_time']=task_detail['report_time'] report_dict['xnr_user_no']=task_detail['xnr_user_no'] report_dict['event_name']=task_detail['event_name'] report_dict['uid']=task_detail['uid'] report_dict['nick_name']=get_user_nickname(task_detail['uid']) weibo_list=[] user_list=[] # print 'type:',type(task_detail['weibo_info']),task_detail['weibo_info'] weibo_info=task_detail['weibo_info'] for item in weibo_info: item['timestamp'] = int(item['timestamp']) flow_text_index_name = flow_text_index_name_pre + ts2datetime(item['timestamp']) try: weibo_result=es_flow_text.get(index=flow_text_index_name,doc_type=flow_text_index_type,id=item['mid'])['_source'] weibo_result['nick_name']=get_user_nickname(weibo_result['uid']) weibo_list.append(weibo_result) except: if task_detail['report_type']==u'人物': weibo_user_warning_index_name = weibo_user_warning_index_name_pre + ts2datetime(item['timestamp']) weibo_user_warming_id=task_detail['xnr_user_no']+'_'+task_detail['uid'] try: weibo_user_result=es_xnr.get(index=weibo_user_warning_index_name,doc_type=weibo_user_warning_index_type,id=weibo_user_warming_id)['_source'] user_warning_content=json.dumps(weibo_user_result['content']) for content in user_warning_content: if content['mid'] == item['mid']: weibo_list.append(content) else: pass except: print 'user_error!' elif task_detail['report_type']==u'言论': weibo_speech_warning_index_name = weibo_speech_warning_index_name_pre + ts2datetime(item['timestamp']) try: weibo_speech_result=es_xnr.get(index=weibo_speech_warning_index_name,doc_type=weibo_speech_warning_index_type,id=task_detail['xnr_user_no']+'_'+item['mid'])['_source'] report_dict['uid']=weibo_speech_result['uid'] weibo_list.append(weibo_speech_result) except: # weibo_timing_warning_index_name = weibo_timing_warning_index_name_pre + ts2datetime(item['timestamp']) print 'speech_error!' elif task_detail['report_type']==u'事件': weibo_event_warning_index_name = weibo_event_warning_index_name_pre + ts2datetime(item['timestamp']) event_warning_id = task_detail['xnr_user_no']+'_'+task_detail['event_name'] try: event_result=es_xnr.get(index=weibo_event_warning_index_name,doc_type=weibo_event_warning_index_type,id=event_warning_id)['_source'] event_content=json.dumps(event_result['main_weibo_info']) for event in event_content: if event['mid'] == item['mid']: weibo_list.append(event) else: pass except: print 'event_error!' elif task_detail['report_type']==u'时间': year = ts2yeartime(item['timestamp']) weibo_timing_warning_index_name = weibo_timing_warning_index_name_pre + year +'_' + task_detail['date_time'] try: time_result=es_xnr.search(index=weibo_timing_warning_index_name,doc_type=weibo_timing_warning_index_type,query_body={'query':{'match_all':{}}})['hits']['hits'] time_content=[] for timedata in time_result: for data in timedata['weibo_date_warming_content']: if data['mid'] == item['mid']: weibo_list.append(data) else: pass except: print 'time_error!' user_info=task_detail['user_info'] if user_info: for uid in user_info: user=dict() try: user_result=es_user_profile.get(index=profile_index_name,doc_type=profile_index_type,id=uid)['_source'] user['uid']=uid user['nick_name']=user_result['nick_name'] user['fansnum']=user_result['fansnum'] user['friendsnum']=user_result['friendsnum'] user['photo_url']=user_result['photo_url'] user_list.append(user) except: user['uid']=uid user['nick_name']='' user['fansnum']=0 user['friendsnum']=0 user['photo_url']='' user_list.append(user) print 'user_list error!' else: pass report_content=dict() report_content['user_list']=user_list report_content['weibo_list']=weibo_list report_dict['report_content']=json.dumps(report_content) report_id='' if task_detail['report_type'] == u'言论': report_id=weibo_info[0]['mid'] elif task_detail['report_type'] == u'人物': report_id=task_detail['xnr_user_no']+'_'+task_detail['uid'] elif task_detail['report_type'] == u'事件': report_id=task_detail['xnr_user_no']+'_'+task_detail['event_name'] elif task_detail['report_type'] == u'时间': # print weibo_info if weibo_info: report_id=weibo_info[0]['mid'] else: report_id=str(task_detail['report_time']) if weibo_list: report_mark=True else: report_mark=False #预警上报后不再显示问题 now_time=int(time.time()) weibo_report_management_index_name = weibo_report_management_index_name_pre + ts2datetime(now_time) if es_xnr.indices.exists(index=weibo_report_management_index_name): pass else: weibo_report_management_mappings() if report_id and report_mark: try: es_xnr.index(index=weibo_report_management_index_name,doc_type=weibo_report_management_index_type,id=report_id,body=report_dict) mark=True except: mark=False else: mark=False return mark