def lookup_xnr_friends(xnr_user_no): try: xnr_result=es_xnr_2.get(index=fb_xnr_fans_followers_index_name,doc_type=fb_xnr_fans_followers_index_type,id=xnr_user_no)['_source'] lookup_list=xnr_result['fans_list'] except: lookup_list=[] return lookup_list
def lookup_xnr_concernedusers(xnr_user_no): try: result=es_xnr_2.get(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,id=xnr_user_no) followers_list=result['_source']['followers_list'] except: followers_list=[] return followers_list
def get_submit_tweet_tw(task_detail): text = task_detail['text'] tweet_type = task_detail['tweet_type'] xnr_user_no = task_detail['xnr_user_no'] es_xnr_result = es.get(index=tw_xnr_index_name, doc_type=tw_xnr_index_type, id=xnr_user_no)['_source'] tw_mail_account = es_xnr_result['tw_mail_account'] tw_phone_account = es_xnr_result['tw_phone_account'] password = es_xnr_result['password'] if tw_phone_account: account_name = tw_phone_account elif tw_mail_account: account_name = tw_mail_account else: account_name = False if account_name: mark = tw_publish(account_name, password, text, tweet_type, xnr_user_no) else: mark = False return mark
def judge_tw_follow_type(xnr_user_no, uid): exist_item = es_fb_tw.exists(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,\ id=xnr_user_no) if not exist_item: tw_type = 'stranger' else: es_get = es_fb_tw.get(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,\ id=xnr_user_no)['_source'] fans_list = '' if es_get.has_key('fans_list'): fans_list = es_get['fans_list'] followers_list = '' if es_get.has_key('followers_list'): followers_list = es_get['followers_list'] if uid in fans_list: if uid in followers_list: tw_type = 'friends' else: tw_type = 'followed' elif uid in followers_list: tw_type = 'follow' else: tw_type = 'stranger' return tw_type
def get_unfollow_operate_fb(task_detail): xnr_user_no = task_detail['xnr_user_no'] uid = task_detail['uid'] es_xnr_result = es.get(index=fb_xnr_index_name,doc_type=fb_xnr_index_type,id=xnr_user_no)['_source'] fb_mail_account = es_xnr_result['fb_mail_account'] fb_phone_account = es_xnr_result['fb_phone_account'] password = es_xnr_result['password'] if fb_phone_account: account_name = fb_phone_account elif fb_mail_account: account_name = fb_mail_account else: account_name = False if account_name: mark = fb_unfollow(account_name, password, uid, xnr_user_no) else: mark = False return mark
def get_retweet_operate_fb(task_detail): text = task_detail['text'] tweet_type = task_detail['tweet_type'] xnr_user_no = task_detail['xnr_user_no'] _id = task_detail['r_fid'] #_id = ?????? uid = task_detail['r_uid'] es_xnr_result = es.get(index=fb_xnr_index_name,doc_type=fb_xnr_index_type,id=xnr_user_no)['_source'] fb_mail_account = es_xnr_result['fb_mail_account'] fb_phone_account = es_xnr_result['fb_phone_account'] password = es_xnr_result['password'] if fb_phone_account: account_name = fb_phone_account elif fb_mail_account: account_name = fb_mail_account else: account_name = False if account_name: mark = fb_retweet(account_name, password, _id, uid, text, tweet_type, xnr_user_no) else: mark = False return mark
def get_delete_friend(task_detail): xnr_user_no = task_detail['xnr_user_no'] uid = task_detail['uid'] es_xnr_result = es.get(index=fb_xnr_index_name,doc_type=fb_xnr_index_type,id=xnr_user_no)['_source'] fb_mail_account = es_xnr_result['fb_mail_account'] fb_phone_account = es_xnr_result['fb_phone_account'] password = es_xnr_result['password'] if fb_phone_account: account_name = fb_phone_account elif fb_mail_account: account_name = fb_mail_account else: account_name = False if account_name: mark = fb_delete_friend(account_name, password, uid) #mark = fb_message('8618348831412','Z1290605918', text, uid) else: mark = False return mark
def get_follow_operate_fb(task_detail): trace_type = task_detail['trace_type'] xnr_user_no = task_detail['xnr_user_no'] uid = task_detail['uid'] es_xnr_result = es.get(index=fb_xnr_index_name, doc_type=fb_xnr_index_type, id=xnr_user_no)['_source'] fb_mail_account = es_xnr_result['fb_mail_account'] fb_phone_account = es_xnr_result['fb_phone_account'] password = es_xnr_result['password'] if fb_phone_account: account_name = fb_phone_account elif fb_mail_account: account_name = fb_mail_account else: account_name = False if account_name: mark = fb_follow(account_name, password, uid, xnr_user_no, trace_type) #mark = fb_follow('13520874771', '13018119931126731x', uid, xnr_user_no, trace_type) else: mark = False return mark
def get_daily_recommend_tweets(theme, sort_item): if S_TYPE == 'test': now_ts = datetime2ts(S_DATE_TW) else: now_ts = int(time.time()) datetime = ts2datetime(now_ts) index_name = daily_interest_index_name_pre + '_' + datetime theme_en = daily_ch2en[theme] es_results = es.get(index=index_name, doc_type=daily_interest_index_type, id=theme_en)['_source'] content = json.loads(es_results['content']) results_all = [] for result in content: #result = result['_source'] uid = result['uid'] nick_name, photo_url = tw_uid2nick_name_photo(uid) result['nick_name'] = nick_name result['photo_url'] = photo_url results_all.append(result) return results_all
def load_xnr_info(): res = [] search_res = es.search(fb_xnr_index_name, fb_xnr_index_type, {'size': 999})['hits']['hits'] for item in search_res: source = item['_source'] fb_mail_account = source.get('fb_mail_account', '') fb_phone_account = source.get('fb_phone_account', '') account = '' if fb_mail_account: account = fb_mail_account elif fb_phone_account: account = fb_phone_account if account: xnr_user_no = source.get('xnr_user_no', '') try: friends_list = es.get( index=fb_xnr_fans_followers_index_name, doc_type=fb_xnr_fans_followers_index_type, id=xnr_user_no)['_source']['fans_list'] except: friends_list = [] info = { 'root_uid': source.get('uid', ''), 'root_nick_name': source.get('nick_name', ''), 'xnr_user_no': xnr_user_no, 'account': account, 'password': source.get('password', ''), 'friends_list': friends_list, 'retry_times': 0, 'remark': '', } res.append(info) return res
def get_show_trace_followers(xnr_user_no): es_get_result = es.get(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,\ id=xnr_user_no)['_source'] trace_follow_list = es_get_result['trace_follow_list'] weibo_user_info = [] if trace_follow_list: mget_results = es.mget(index=twitter_user_index_name,doc_type=twitter_user_index_type,\ body={'ids':trace_follow_list})['docs'] # print 'mget_results::',mget_results for result in mget_results: if result['found']: weibo_user_info.append(result['_source']) else: uid = result['_id'] weibo_user_info.append({ 'uid': uid, 'statusnum': 0, 'fansnum': 0, 'friendsnum': 0, 'photo_url': '', 'sex': '', 'nick_name': uid, 'user_location': '' }) else: weibo_user_info = [] return weibo_user_info
def get_bussiness_recomment_tweets(xnr_user_no, sort_item): get_results = es.get(index=tw_xnr_index_name, doc_type=tw_xnr_index_type, id=xnr_user_no)['_source'] monitor_keywords = get_results['monitor_keywords'] monitor_keywords_list = monitor_keywords.split(',') if sort_item == 'timestamp': sort_item_new = 'timestamp' es_results = get_tweets_from_flow(monitor_keywords_list, sort_item_new) elif sort_item == 'sensitive_info': sort_item_new = 'sensitive' es_results = get_tweets_from_flow(monitor_keywords_list, sort_item_new) elif sort_item == 'sensitive_user': sort_item_new = 'sensitive' es_results = get_tweets_from_user_portrait(monitor_keywords_list, sort_item_new) elif sort_item == 'influence_info': sort_item_new = 'share' es_results = get_tweets_from_flow(monitor_keywords_list, sort_item_new) elif sort_item == 'influence_user': sort_item_new = 'influence' es_results = get_tweets_from_bci(monitor_keywords_list, sort_item_new) return es_results
def get_follow_operate_tw(task_detail): trace_type = task_detail['trace_type'] xnr_user_no = task_detail['xnr_user_no'] #nick_name = task_detail['nick_name'] uid = task_detail['uid'] es_xnr_result = es.get(index=tw_xnr_index_name, doc_type=tw_xnr_index_type, id=xnr_user_no)['_source'] tw_mail_account = es_xnr_result['tw_mail_account'] tw_phone_account = es_xnr_result['tw_phone_account'] password = es_xnr_result['password'] if tw_phone_account: account_name = tw_phone_account elif tw_mail_account: account_name = tw_mail_account else: account_name = False if account_name: mark = tw_follow(account_name, password, uid, xnr_user_no, trace_type) else: mark = False return mark
def get_private_operate_tw(task_detail): xnr_user_no = task_detail['xnr_user_no'] text = task_detail['text'] uid = task_detail['uid'] es_xnr_result = es.get(index=tw_xnr_index_name, doc_type=tw_xnr_index_type, id=xnr_user_no)['_source'] tw_mail_account = es_xnr_result['tw_mail_account'] tw_phone_account = es_xnr_result['tw_phone_account'] password = es_xnr_result['password'] if tw_phone_account: account_name = tw_phone_account elif tw_mail_account: account_name = tw_mail_account else: account_name = False if account_name: mark = tw_message(account_name, password, text, uid) else: mark = False return mark
def get_at_operate_tw(task_detail): text = task_detail['text'] tweet_type = task_detail['tweet_type'] xnr_user_no = task_detail['xnr_user_no'] # user_name = task_detail['nick_name'] es_xnr_result = es.get(index=tw_xnr_index_name, doc_type=tw_xnr_index_type, id=xnr_user_no)['_source'] tw_mail_account = es_xnr_result['tw_mail_account'] tw_phone_account = es_xnr_result['tw_phone_account'] password = es_xnr_result['password'] if tw_phone_account: account_name = tw_phone_account elif tw_mail_account: account_name = tw_mail_account else: account_name = False if account_name: mark = tw_mention(account_name, password, text, xnr_user_no, tweet_type) else: mark = False return mark
def get_like_operate_tw(task_detail): xnr_user_no = task_detail['xnr_user_no'] _id = task_detail['r_fid'] #_id = ?????? #uid = task_detail['r_uid'] es_xnr_result = es.get(index=tw_xnr_index_name, doc_type=tw_xnr_index_type, id=xnr_user_no)['_source'] tw_mail_account = es_xnr_result['tw_mail_account'] tw_phone_account = es_xnr_result['tw_phone_account'] password = es_xnr_result['password'] if tw_phone_account: account_name = tw_phone_account elif tw_mail_account: account_name = tw_mail_account else: account_name = False if account_name: mark = tw_like(account_name, password, _id) else: mark = False return mark
def tw_save_to_fans_follow_ES(xnr_user_no,uid,follow_type,trace_type): try: results = es_fb_tw.get(index=fb_xnr_fans_followers_index_name,doc_type=fb_xnr_fans_followers_index_type,\ id=xnr_user_no) results = results["_source"] except: results = [] if follow_type == 'follow': if trace_type == 'trace_follow': try: if results: # 添加追随关注 try: trace_follow_uids = results['trace_follow_list'] trace_follow_uids_set = set(trace_follow_uids) trace_follow_uids_set.add(uid) trace_follow_uids = list(trace_follow_uids_set) except: trace_follow_uids = [uid] # # 添加普通关注 # try: # followers_uids = results['followers_list'] # followers_uids_set = set(followers_uids) # followers_uids_set.add(uid) # followers_uids = list(followers_uids_set) # except: # followers_uids = [uid] # results['followers_list'] = followers_uids results['trace_follow_list'] = trace_follow_uids es_fb_tw.update(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,\ id=xnr_user_no,body={'doc':results}) else: results['trace_follow_list'] = [uid] results['followers_list'] = [uid] es_fb_tw.index(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,\ body=results,id=xnr_user_no) except: return False elif follow_type == 'unfollow': try: followers_uids = results['trace_follow_pre_list'] followers_uids = list(set(followers_uids).difference(set([uid]))) results['trace_follow_pre_list'] = followers_uids es_fb_tw.update(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,\ id=xnr_user_no,body={'doc':results}) except: return False return True
def get_comment_operate_tw(task_detail): text = task_detail['text'] tweet_type = task_detail['tweet_type'] xnr_user_no = task_detail['xnr_user_no'] _id = task_detail['r_fid'] #_id = ?????? uid = task_detail['r_uid'] #nick_name = task_detail['nick_name'] es_xnr_result = es.get(index=tw_xnr_index_name, doc_type=tw_xnr_index_type, id=xnr_user_no)['_source'] tw_mail_account = es_xnr_result['tw_mail_account'] tw_phone_account = es_xnr_result['tw_phone_account'] password = es_xnr_result['password'] if tw_phone_account: account_name = tw_phone_account elif tw_mail_account: account_name = tw_mail_account else: account_name = False if account_name: print '123' mark = tw_comment(account_name, password, _id, uid, text, tweet_type, xnr_user_no) else: mark = False return mark
def influence_cover(uid, current_time): #index_name = facebook_feedback_friends_index_name # 没有列表 try: es_search = es.get(index=facebook_user_index_name,doc_type=facebook_user_index_type,\ id=uid)['_source'] try: likes = es_search['likes'] except: likes = 0 try: talking_about_count = es_search['talking_about_count'] except: talking_about_count = 0 cover_num = likes + talking_about_count if not cover_num: cover_num = 1 except: cover_num = 1 # 取log之后为0 return cover_num
def lookup_xnr_fans_followers(xnr_user_no,lookup_type): try: xnr_result=es_xnr_2.get(index=tw_xnr_fans_followers_index_name,doc_type=tw_xnr_fans_followers_index_type,id=xnr_user_no)['_source'] lookup_list=xnr_result[lookup_type] except: lookup_list=[] return lookup_list
def lookup_xnr_uid(xnr_user_no): try: xnr_result=es_xnr_2.get(index=tw_xnr_index_name,doc_type=tw_xnr_index_type,id=xnr_user_no)['_source'] xnr_uid=xnr_result['uid'] except: xnr_uid='' return xnr_uid
def get_user_nickname(uid): try: result=es_xnr_2.get(index=twitter_user_index_name,doc_type=twitter_user_index_type,id=uid) user_name=result['_source']['username'] except: user_name='' return user_name
def get_un_trace_follow_operate(xnr_user_no,uid_string,nick_name_string): mark = False fail_nick_name_list = [] fail_uids = [] if uid_string: uid_list = uid_string.encode('utf-8').split(',') elif nick_name_string: nick_name_list = nick_name_string.encode('utf-8').split(',') uid_list = [] for nick_name in nick_name_list: query_body = { 'query':{ 'filtered':{ 'filter':{ 'term':{'nick_name':nick_name} } } }, '_source':['uid'] } try: uid_results = es.search(index=facebook_user_index_name,doc_type=facebook_user_index_type,\ body=query_body)['hits']['hits'] uid_result = uid_result[0]['_source'] uid = uid_result['uid'] uid_list.append(uid) except: fail_nick_name_list.append(nick_name) try: result = es.get(index=fb_xnr_fans_followers_index_name,doc_type=fb_xnr_fans_followers_index_type,\ id=xnr_user_no)['_source'] trace_follow_list = result['trace_follow_list'] # 共同uids comment_uids = list(set(trace_follow_list).intersection(set(uid_list))) # 取消失败uid fail_uids = list(set(comment_uids).difference(set(uid_list))) # 求差 trace_follow_list = list(set(trace_follow_list).difference(set(uid_list))) es.update(index=fb_xnr_fans_followers_index_name,doc_type=fb_xnr_fans_followers_index_type,\ id=xnr_user_no,body={'doc':{'trace_follow_list':trace_follow_list}}) mark = True except: mark = False return [mark,fail_uids,fail_nick_name_list]
def tw_xnr_user_no2uid(xnr_user_no): try: result = es_fb_tw.get(index=tw_xnr_index_name,doc_type=tw_xnr_index_type,id=xnr_user_no)['_source'] uid = result['uid'] except: uid = '' return uid
def tw_uid2nick_name_photo(uid): uname_photo_dict = {} try: user = es_fb_tw.get(index=twitter_user_index_name,doc_type=twitter_user_index_type,id=uid)['_source'] nick_name = user['username'] photo_url = user['profile_image_url_https'] except: nick_name = uid photo_url = '' return nick_name,photo_url
def fb_uid2nick_name_photo(uid): uname_photo_dict = {} try: user = es_fb_tw.get(index=facebook_user_index_name,doc_type=facebook_user_index_type,id=uid)['_source'] nick_name = user['name'] photo_url = ''#user['photo_url'] except: nick_name = uid photo_url = '' return nick_name,photo_url
def get_hot_subopinion(xnr_user_no, task_id): task_id_new = xnr_user_no + '_' + task_id es_task = [] try: es_task = es.get(index=tw_hot_keyword_task_index_name,doc_type=tw_hot_keyword_task_index_type,\ id=task_id_new)['_source'] except: return '尚未提交计算' if es_task: if es_task['compute_status'] != 2: return '正在计算' else: es_result = es.get(index=tw_hot_subopinion_results_index_name,doc_type=tw_hot_subopinion_results_index_type,\ id=task_id_new)['_source'] if es_result: contents = json.loads(es_result['subopinion_tw']) return contents
def get_submit_tweet_fb(task_detail): print 'get_submit_tweet_fb,start execute=========================' text = task_detail['text'] tweet_type = task_detail['tweet_type'] channel = task_detail['channel'] operate_type = task_detail['operate_type'] xnr_user_no = task_detail['xnr_user_no'] try: es_xnr_result = es.get(index=fb_xnr_index_name, doc_type=fb_xnr_index_type, id=xnr_user_no)['_source'] except Exception as e: print e print es_xnr_result fb_mail_account = es_xnr_result['fb_mail_account'] fb_phone_account = es_xnr_result['fb_phone_account'].strip() password = str(es_xnr_result['password'].strip()) print type(password), password print type('13018119931126731x'), '13018119931126731x' print es.search('fb_xnr', 'user', {}) if fb_phone_account: account_name = str(fb_phone_account) print type(account_name), account_name print type('+8613520874771'), '+8613520874771' elif fb_mail_account: account_name = fb_mail_account else: account_name = False if account_name: print '--------------------------------==================================-------------------------------------------------------' # add params to aliyunredis kn try: fb_tweet_params_dict = {} fb_tweet_params_dict["account_name"] = account_name fb_tweet_params_dict["password"] = password fb_tweet_params_dict["text"] = text fb_tweet_params_dict["tweet_type"] = tweet_type fb_tweet_params_dict["xnr_user_no"] = xnr_user_no fb_tweet_params_dict["channel"] = channel fb_tweet_params_dict["operate"] = operate_type print FB_TWEET_PARAMS, '===================================================fb params' ali_re.lpush(FB_TWEET_PARAMS, json.dumps(fb_tweet_params_dict)) mark = fb_publish(account_name, password, text, tweet_type, xnr_user_no) except Exeption as e: print e #mark = fb_publish('+8613520874771', '13018119931126731x', text, tweet_type, xnr_user_no) else: mark = False return mark
def influence_trust(uid): try: es_search = es.get(index=twitter_user_index_name,doc_type=twitter_user_index_type,\ id=uid)['_source'] influence_trust = es_search['is_verified'] except: influence_trust = 0 return influence_trust
def get_retweet_operate_tw(task_detail): text = task_detail['text'] tweet_type = task_detail['tweet_type'] xnr_user_no = task_detail['xnr_user_no'] channel = task_detail['channel'] operate_type = task_detail['operate_type'] _id = task_detail['r_fid'] #_id = ?????? uid = task_detail['r_uid'] es_xnr_result = es.get(index=tw_xnr_index_name, doc_type=tw_xnr_index_type, id=xnr_user_no)['_source'] tw_mail_account = es_xnr_result['tw_mail_account'] tw_phone_account = es_xnr_result['tw_phone_account'] password = es_xnr_result['password'] if tw_phone_account: account_name = tw_phone_account elif tw_mail_account: account_name = tw_mail_account else: account_name = False if account_name: print '--------------------------------------------====================================--------------------------------------------' # add params to aliyunredis kn try: tw_tweet_params_dict = {} tw_tweet_params_dict['account_name'] = account_name tw_tweet_params_dict['password'] = password tw_tweet_params_dict['_id'] = _id tw_tweet_params_dict['uid'] = uid tw_tweet_params_dict['text'] = text tw_tweet_params_dict['tweet_type'] = tweet_type tw_tweet_params_dict['xnr_user_no'] = xnr_user_no tw_tweet_params_dict['channel'] = channel tw_tweet_params_dict['operate'] = operate_type print TW_TWEET_PARAMS, '========================================tw params' ali_re.lpush(TW_TWEET_PARAMS, json.dumps(tw_tweet_params_dict)) print 'push to aliyun redis sucessful' mark = tw_retweet(account_name, password, _id, uid, text, tweet_type, xnr_user_no) except Exception as e: print e else: mark = False return mark