Example #1
0
def get_add_opinion_corpus(task_detail):

    mark = False

    corpus_name = task_detail['corpus_name']
    corpus_pinyin = pinyin.get(corpus_name, format='strip', delimiter='_')

    item_dict = {}
    item_dict['corpus_name'] = corpus_name
    item_dict['corpus_pinyin'] = corpus_pinyin
    item_dict['submitter'] = task_detail['submitter']
    item_dict['status'] = 0

    try:
        es.get(index=opinion_corpus_index_name,
               doc_type=opinion_corpus_index_type,
               id=corpus_pinyin)

        return 'exists'

    except:

        try:
            es.index(index=opinion_corpus_index_name,
                     doc_type=opinion_corpus_index_type,
                     body=item_dict,
                     id=corpus_pinyin)
            mark = True

            r_r.lpush(opinion_expand_task_queue_name, json.dumps(item_dict))

        except:
            pass

    return mark
Example #2
0
def get_weibohistory_like(task_detail):
    root_mid = task_detail['r_mid']

    xnr_user_no = task_detail['xnr_user_no']
    #print 'xnr_user_no',xnr_user_no
    if not xnr_user_no:
        mark = False
        save_mark = False
        #print mark,save_mark
        return mark, save_mark
    xnr_es_result = es_xnr.get(index=weibo_xnr_index_name,
                               doc_type=weibo_xnr_index_type,
                               id=xnr_user_no)['_source']
    account_name = xnr_es_result['weibo_mail_account']
    password = xnr_es_result['password']
    root_uid = xnr_es_result['uid']

    xnr_result = es_xnr.get(index=weibo_xnr_fans_followers_index_name,
                            doc_type=weibo_xnr_fans_followers_index_type,
                            id=xnr_user_no)['_source']
    if xnr_result['followers_list']:
        followers_list = xnr_result['followers_list']
    else:
        followers_list = []

    if xnr_result['fans_list']:
        fans_list = xnr_result['fans_list']
    else:
        fans_list = []

    #调用点赞函数
    mark = like_tweet_func(account_name, password, root_mid)

    #保存点赞信息至表
    uid = task_detail['uid']
    photo_url = task_detail['photo_url']
    nick_name = task_detail['nick_name']
    timestamp = task_detail['timestamp']
    text = task_detail['text']
    update_time = task_detail['update_time']
    mid = root_uid + '_' + root_mid

    if uid not in followers_list:
        if uid not in fans_list:
            weibo_type = 'stranger'
        else:
            weibo_type = 'fans'
    else:
        if uid not in fans_list:
            weibo_type = 'follow'
        else:
            weibo_type = 'friend'

    like_info = [
        uid, photo_url, nick_name, mid, timestamp, text, root_mid, root_uid,
        weibo_type, update_time
    ]
    save_mark = save_xnr_like(like_info)

    return mark, save_mark
Example #3
0
def domain_create_task(domain_name,
                       create_type,
                       create_time,
                       submitter,
                       description,
                       remark,
                       compute_status=0):
    task_id = pinyin.get(domain_name, format='strip', delimiter='_')
    try:
        es.get(index=fb_domain_index_name,
               doc_type=fb_domain_index_type,
               id=task_id)['_source']
        return 'domain name exists!'
    except:
        try:
            domain_task_dict = dict()
            domain_task_dict['domain_pinyin'] = pinyin.get(domain_name,
                                                           format='strip',
                                                           delimiter='_')
            domain_task_dict['domain_name'] = domain_name
            domain_task_dict['create_type'] = json.dumps(create_type)
            domain_task_dict['create_time'] = create_time
            domain_task_dict['submitter'] = submitter
            domain_task_dict['description'] = description
            domain_task_dict['remark'] = remark
            domain_task_dict['compute_status'] = compute_status
            # print 'domain_task_dict'
            # print domain_task_dict
            # print 'before: r.lrange'
            # print r.lrange(fb_target_domain_detect_queue_name,0,100)
            r.lpush(fb_target_domain_detect_queue_name,
                    json.dumps(domain_task_dict))
            # print 'after: r.lrange'
            # print r.lrange(fb_target_domain_detect_queue_name,0,100)
            item_exist = dict()
            item_exist['domain_pinyin'] = domain_task_dict['domain_pinyin']
            item_exist['domain_name'] = domain_task_dict['domain_name']
            item_exist['create_type'] = domain_task_dict['create_type']
            item_exist['create_time'] = domain_task_dict['create_time']
            item_exist['submitter'] = domain_task_dict['submitter']
            item_exist['description'] = domain_task_dict['description']
            item_exist['remark'] = domain_task_dict['remark']
            item_exist['group_size'] = ''
            item_exist['compute_status'] = 0  # 存入创建信息
            print es.index(index=fb_domain_index_name,
                           doc_type=fb_domain_index_type,
                           id=item_exist['domain_pinyin'],
                           body=item_exist)
            mark = True
        except Exception, e:
            print e
            mark = False
        return mark
Example #4
0
def get_save_step_three_1(task_detail):
    task_id = task_detail['task_id']
    # query_body = {'query':{'match_all':{}},'sort':{'user_no':{'order':'desc'}}}
    # es_result = es.search(index=fb_xnr_index_name,doc_type=fb_xnr_index_type,body=query_body)['hits']['hits']
    # task_id = es_result[0]['_source']['xnr_user_no']
    item_exist = es.get(index=fb_xnr_index_name,
                        doc_type=fb_xnr_index_type,
                        id=task_id)['_source']

    item_exist['uid'] = task_detail['id']
    item_exist['nick_name'] = task_detail['nick_name']
    item_exist['fb_mail_account'] = task_detail['fb_mail_account']
    item_exist['fb_phone_account'] = task_detail['fb_phone_account']
    item_exist['password'] = task_detail['password']
    item_exist['career'] = task_detail['career']
    item_exist['description'] = task_detail['description']
    item_exist['age'] = task_detail['age']
    item_exist['location'] = task_detail['location']
    item_exist['create_status'] = 2  # 创建完成
    # 更新 fb_xnr表
    print es.update(index=fb_xnr_index_name,
                    doc_type=fb_xnr_index_type,
                    id=task_id,
                    body={'doc': item_exist})
    mark = True
    return mark
Example #5
0
def get_role_info(domain_pinyin, role_name):
    role_en = fb_domain_ch2en_dict(role_name)
    role_info_id = domain_pinyin + '_' + role_en
    role_info = es.get(index=fb_domain_index_name,
                       doc_type=fb_domain_index_type,
                       id=role_info_id)['_source']
    return role_info
Example #6
0
def lookup_xnr_fans_followers(user_id,lookup_type):
    try:
        xnr_result=es_xnr.get(index=weibo_xnr_fans_followers_index_name,doc_type=weibo_xnr_fans_followers_index_type,id=user_id)['_source']
        lookup_list=xnr_result[lookup_type]
    except:
        lookup_list=[]
    return lookup_list
Example #7
0
def get_safe_qq(xnr_user_no,start_ts,end_ts):

    speak_dict = {}
    speak_dict['speak_day'] = {}
    speak_dict['speak_total'] = {}

    start_date = ts2datetime(start_ts)
    end_date = ts2datetime(end_ts)

    index_name_list = get_timeset_indexset_list(qq_xnr_history_count_index_name_pre,start_date,end_date)

    for index_name in index_name_list:
        try:
            get_result = es_xnr.get(index=index_name,doc_type=qq_xnr_history_count_index_type,\
                        id=xnr_user_no)['_source']

            timestamp = get_result['timestamp']

            speak_dict['speak_day'][timestamp] = result['daily_post_num']
            speak_dict['speak_total'][timestamp] = result['total_post_num']
            speak_dict['mark'] = result['safe']

        except:

            date = index_name[-10:]
            timestamp = datetime2ts(date)
            speak_dict['speak_day'][timestamp] = 0
            speak_dict['speak_total'][timestamp] = 0
            speak_dict['mark'] = 0.0

    return speak_dict
Example #8
0
def get_domain_info(domain_pinyin):

    domain_info = es.get(index=weibo_domain_index_name,
                         doc_type=weibo_domain_index_type,
                         id=domain_pinyin)['_source']

    return domain_info
Example #9
0
def get_influence_at_num(xnr_user_no,start_ts,end_ts):

    at_dict = {}
    at_dict['at_day'] = {}
    at_dict['at_total'] = {}


    start_date = ts2datetime(start_ts)
    end_date = ts2datetime(end_ts)

    index_name_list = get_timeset_indexset_list(qq_xnr_history_count_index_name_pre,start_date,end_date)
    
    for index_name in index_name_list:

        try:
            get_result = es_xnr.get(index=index_name,doc_type=qq_xnr_history_count_index_type,\
                    id=xnr_user_no)['_source']

            timestamp = get_result['timestamp']
            at_dict['at_day'][timestamp] = get_result['daily_be_at_num']
            at_dict['at_total'][timestamp] = get_result['total_be_at_num']
            at_dict['mark'] = get_result['influence']


        except:

            date = index_name[-10:]
            timestamp = datetime2ts(date)

            at_dict['at_day'][timestamp] = 0
            at_dict['at_total'][timestamp] = 0
            at_dict['mark'] = 0.0

    return at_dict
Example #10
0
def lookup_xnr_uid(xnr_user_no):
    try:
        xnr_result=es_xnr.get(index=weibo_xnr_index_name,doc_type=weibo_xnr_index_type,id=xnr_user_no)['_source']
        xnr_uid=xnr_result['uid']
    except:
        xnr_uid=''
    return xnr_uid
Example #11
0
def lookup_weiboxnr_concernedusers(weiboxnr_id):
    try:
        result=es_xnr.get(index=weibo_xnr_fans_followers_index_name,doc_type=weibo_xnr_fans_followers_index_type,id=weiboxnr_id)
        followers_list=result['_source']['followers_list']
    except:
    	followers_list=[]
    return followers_list
Example #12
0
def get_user_nickname(uid):
    try:
        result=es_xnr.get(index=profile_index_name,doc_type=profile_index_type,id=uid)
        user_name=result['_source']['nick_name']
    except:
        user_name=''
    return user_name
Example #13
0
def change_select_corpus(corpus_id, corpus_type, theme_daily_name,
                         create_type):
    corpus_result = es.get(index=weibo_xnr_corpus_index_name,
                           doc_type=weibo_xnr_corpus_index_type,
                           id=corpus_id)['_source']
    text = corpus_result['text']
    uid = corpus_result['uid']
    mid = corpus_result['mid']
    timestamp = corpus_result['timestamp']
    retweeted = corpus_result['retweeted']
    comment = corpus_result['comment']
    like = corpus_result['like']

    corpus_type = corpus_type
    theme_daily_name = theme_daily_name
    create_type = create_type

    try:
        es.update(index=weibo_xnr_corpus_index_name,doc_type=weibo_xnr_corpus_index_type,id=corpus_id,\
            body={"doc":{'corpus_type':corpus_type,'theme_daily_name':theme_daily_name,'text':text,\
            'uid':uid,'mid':mid,'timestamp':timestamp,'retweeted':retweeted,'comment':comment,'like':like,'create_type':create_type}})
        result = True
    except:
        result = False
    return result
Example #14
0
def show_select_corpus(corpus_id):
    result=es.get(index=weibo_xnr_corpus_index_name,doc_type=weibo_xnr_corpus_index_type,id=corpus_id)
    results=[]
    for item in result:
        item['_source']['id']=item['_id']
        results.append(item['_source'])
    return results
Example #15
0
def get_role2feature_info(domain_name, role_name):
    domain_pinyin = pinyin.get(domain_name, format='strip', delimiter='_')
    role_name_en = domain_ch2en_dict[role_name]
    _id = domain_pinyin + '_' + role_name_en
    try:
        es_result = es.get(index=weibo_role_index_name,
                           doc_type=weibo_role_index_type,
                           id=_id)['_source']

        feature_info_dict = es_result
        feature_filter_dict = dict()

        feature_filter_dict['political_side'] = json.loads(
            feature_info_dict['political_side'])
        try:
            feature_filter_dict['psy_feature'] = json.loads(
                feature_info_dict['psy_feature'])
        except:
            feature_filter_dict['psy_feature'] = []

        #print
        return feature_filter_dict

    except:
        return []
Example #16
0
def get_penetration_qq(xnr_user_no,start_ts,end_ts):

    follow_group_sensitive = {}
    follow_group_sensitive['sensitive_info'] = {}

    start_date = ts2datetime(start_ts)
    end_date = ts2datetime(end_ts)

    index_name_list = get_timeset_indexset_list(qq_xnr_history_count_index_name_pre,start_date,end_date)

    for index_name in index_name_list:

        try:
            get_result = es_xnr.get(index=index_name,doc_type=qq_xnr_history_count_index_type,\
                        id=xnr_user_no)['_source']
            
            timestamp = get_result['timestamp']

            follow_group_sensitive['sensitive_info'][timestamp] = get_result['daily_sensitive_num']
            follow_group_sensitive['mark'] = get_result['penetration']

        except:

            date = index_name[-10:]
            timestamp = datetime2ts(date)
            follow_group_sensitive['sensitive_info'][timestamp] = 0.0
            follow_group_sensitive['mark'] = 0.0

    return follow_group_sensitive
Example #17
0
def get_xnr_info_new(xnr_user_no):

    results = es.get(index=weibo_xnr_index_name,
                     doc_type=weibo_xnr_index_type,
                     id=xnr_user_no)['_source']

    return results
Example #18
0
def get_show_domain_description(domain_name):
    domain_pinyin = pinyin.get(domain_name,format='strip',delimiter='_')
    es_result = es.get(index=fb_domain_index_name,doc_type=fb_domain_index_type,\
                id=domain_pinyin)['_source']
    item = {}
    item['group_size'] = es_result['group_size']
    item['description'] = es_result['description']
    topic_preference_list = json.loads(es_result['topic_preference'])
    topic_preference_list_chinese = []
    for topic_preference_item in topic_preference_list:
        topic_preference_item_chinese = fb_tw_topic_en2ch_dict[topic_preference_item[0]]
        topic_preference_list_chinese.append([topic_preference_item_chinese,topic_preference_item[1]])

    item['topic_preference'] = topic_preference_list_chinese
    item['word_preference'] = json.loads(es_result['top_keywords'])
    role_distribute_list = json.loads(es_result['role_distribute'])
    role_distribute_list_chinese = []
    for role_distribute_item in role_distribute_list:
        role_distribute_item_chinese = fb_domain_en2ch_dict[role_distribute_item[0]]
        role_distribute_list_chinese.append([role_distribute_item_chinese,role_distribute_item[1]])

    item['role_distribute'] = role_distribute_list_chinese
    political_side_list = json.loads(es_result['political_side'])
    political_side_list_chinese = []
    for political_side_item in political_side_list:
        if political_side_item[0] == 'mid':
            political_side_list_chinese.append([u'中立',political_side_item[1]])
        elif political_side_item[0] == 'right':
            political_side_list_chinese.append([u'右倾',political_side_item[1]])
        else:
            political_side_list_chinese.append([u'左倾',political_side_item[1]])
    item['political_side'] = political_side_list_chinese
    return item
Example #19
0
def domain_create_task(domain_name,create_type,create_time,submitter,description,remark,compute_status=0):
    
    task_id = pinyin.get(domain_name,format='strip',delimiter='_')

    try:
        es.get(index=weibo_domain_index_name,doc_type=weibo_domain_index_type,id=task_id)['_source']

        return 'domain name exists!'

    except:

        try:
            domain_task_dict = dict()

            #domain_task_dict['xnr_user_no'] = xnr_user_no
            domain_task_dict['domain_pinyin'] = pinyin.get(domain_name,format='strip',delimiter='_')
            domain_task_dict['domain_name'] = domain_name
            domain_task_dict['create_type'] = json.dumps(create_type)
            domain_task_dict['create_time'] = create_time
            domain_task_dict['submitter'] = submitter
            domain_task_dict['description'] = description
            domain_task_dict['remark'] = remark
            domain_task_dict['compute_status'] = compute_status

            r.lpush(weibo_target_domain_detect_queue_name,json.dumps(domain_task_dict))

            item_exist = dict()
            
            #item_exist['xnr_user_no'] = domain_task_dict['xnr_user_no']
            item_exist['domain_pinyin'] = domain_task_dict['domain_pinyin']
            item_exist['domain_name'] = domain_task_dict['domain_name']
            item_exist['create_type'] = domain_task_dict['create_type']
            item_exist['create_time'] = domain_task_dict['create_time']
            item_exist['submitter'] = domain_task_dict['submitter']
            item_exist['description'] = domain_task_dict['description']
            item_exist['remark'] = domain_task_dict['remark']
            item_exist['group_size'] = ''
            
            item_exist['compute_status'] = 0  # 存入创建信息
            es.index(index=weibo_domain_index_name,doc_type=weibo_domain_index_type,id=item_exist['domain_pinyin'],body=item_exist)


            mark = True
        except:
            mark =False

        return mark
Example #20
0
def get_show_domain_group_detail_portrait(domain_name):
    domain_pinyin = pinyin.get(domain_name, format='strip', delimiter='_')
    es_result = es.get(index=tw_domain_index_name,doc_type=tw_domain_index_type,\
                id=domain_pinyin)['_source']
    member_uids = es_result['member_uids']
    es_mget_result = es_user_portrait.mget(index=portrait_index_name,doc_type=portrait_index_type,\
                    body={'ids':member_uids})['docs']
    result_all = []
    for result in es_mget_result:
        item = {}
        item['uid'] = ''
        item['nick_name'] = ''
        item['photo_url'] = ''
        item['domain'] = ''
        item['sensitive'] = ''
        item['location'] = ''
        item['fans_num'] = ''
        item['friends_num'] = ''
        # item['gender'] = ''
        item['home_page'] = ""
        item['influence'] = ''
        if result['found']:
            item['uid'] = result['_id']
            result = result['_source']
            if result.has_key('uname'):
                item['nick_name'] = result['uname']
            if result.has_key('photo_url'):
                item['photo_url'] = result['photo_url']
            if result.has_key('domain'):
                item['domain'] = result['domain']
            if result.has_key('sensitive'):
                item['sensitive'] = result['sensitive']
            if result.has_key('location'):
                item['location'] = result['location']
            if result.has_key('fansnum'):
                item['fans_num'] = result['fansnum']
            if result.has_key('friends_num'):
                item['friends_num'] = result['friendsnum']
            # item['gender'] = result['gender']
            if result.has_key('screenname'):
                item['home_page'] = "https://twitter.com/" + result[
                    'screenname']
            if result.has_key('influence'):
                item['influence'] = get_influence_relative(
                    item['uid'], result['influence'])
        # else:
        #     item['uid'] = result['_id']
        #     item['nick_name'] = ''
        #     item['photo_url'] = ''
        #     item['domain'] = ''
        #     item['sensitive'] = ''
        #     item['location'] = ''
        #     item['fans_num'] = ''
        #     item['friends_num'] = ''
        #     # item['gender'] = ''
        #     item['home_page'] = ""
        #     item['influence'] = ''
        result_all.append(item)
    return result_all
Example #21
0
def get_show_domain_role_info(domain_name, role_name):
    domain_pinyin = pinyin.get(domain_name, format='strip', delimiter='_')
    role_en = fb_domain_ch2en_dict[role_name]
    task_id = domain_pinyin + '_' + role_en
    es_result = es.get(index=fb_role_index_name,
                       doc_type=fb_role_index_type,
                       id=task_id)['_source']
    return es_result
Example #22
0
def lookup_xnr_concernedusers(xnr_user_no):
    try:
        result = es_xnr.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
Example #23
0
def get_user_nickname(uid):
    try:
        result = es_xnr.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
Example #24
0
def lookup_xnr_friends(xnr_user_no):
    try:
        xnr_result = es_xnr.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
Example #25
0
def get_my_group_v2(xnr_user_no):

    try:
        es_get_results = es_xnr.get(index=qq_xnr_index_name,doc_type=qq_xnr_index_type,id=xnr_user_no)['_source']
        group_info = json.loads(es_get_results['group_info'])

    except:
        group_info = {}
        
    return group_info
Example #26
0
def get_show_domain_group_detail_portrait(domain_name):
    domain_pinyin = pinyin.get(domain_name, format='strip', delimiter='_')
    es_result = es.get(index=fb_domain_index_name,doc_type=fb_domain_index_type,\
                id=domain_pinyin)['_source']
    member_uids = es_result['member_uids']
    es_mget_result = es_user_portrait.mget(index=portrait_index_name,doc_type=portrait_index_type,\
                    body={'ids':member_uids})['docs']
    result_all = []
    for result in es_mget_result:
        item = {}
        item['uid'] = ''
        item['nick_name'] = ''
        # item['photo_url'] = ''
        item['domain'] = ''
        item['sensitive'] = ''
        item['location'] = ''
        # item['fans_num'] = ''
        # item['friends_num'] = ''
        # item['gender'] = ''
        item['home_page'] = ''
        # item['home_page'] = 'http://weibo.com/'+result['_id']+'/profile?topnav=1&wvr=6&is_all=1'
        item['influence'] = ''
        if result['found']:
            result = result['_source']
            item['uid'] = result['uid']
            item['nick_name'] = result['uname']
            # item['photo_url'] = result['photo_url']
            item['domain'] = result['domain']
            item['sensitive'] = result['sensitive']
            item['location'] = result['location']
            # item['fans_num'] = result['fansnum']
            # item['friends_num'] = result['friendsnum']
            # item['gender'] = result['gender']
            item[
                'home_page'] = "https://www.facebook.com/profile.php?id=" + str(
                    result['uid'])
            # item['home_page'] = 'http://weibo.com/'+result['uid']+'/profile?topnav=1&wvr=6&is_all=1'
            item['influence'] = get_influence_relative(item['uid'],
                                                       result['influence'])
        # else:
        #     item['uid'] = result['_id']
        #     item['nick_name'] = ''
        #     # item['photo_url'] = ''
        #     item['domain'] = ''
        #     item['sensitive'] = ''
        #     item['location'] = ''
        #     # item['fans_num'] = ''
        #     # item['friends_num'] = ''
        #     # item['gender'] = ''
        #     item['home_page'] = "https://www.facebook.com/profile.php?id=" + str(result['_id'])
        #     # item['home_page'] = 'http://weibo.com/'+result['_id']+'/profile?topnav=1&wvr=6&is_all=1'
        #     item['influence'] = ''
        result_all.append(item)
    return result_all
Example #27
0
def get_role_sort_list(domain_name):
    domain_pinyin = pinyin.get(domain_name, format='strip',delimiter='_')
    try:
        es_result = es.get(index=tw_domain_index_name,doc_type=tw_domain_index_type,id=domain_pinyin)['_source']
        role_sort_list_en = json.loads(es_result['role_distribute'])
        role_sort_list_zh = []
        for item in role_sort_list_en:
            role_zh = tw_domain_en2ch_dict[item[0]]
            role_sort_list_zh.append(role_zh)
        return role_sort_list_zh
    except:
        return []
Example #28
0
def get_login_name(xnr_user_no):

    try:
        print 'execut get_login_name function--------------------------------------------------------------------------------'
        get_results = es_xnr.get(index=qq_xnr_index_name,doc_type=qq_xnr_index_type,id=xnr_user_no)['_source']
        print get_results, 'es results-=-=-=-=-=-==-=-=-=========================-----------------------------------------------' 
        qq_number = get_results['qq_number']
        qqbot_port = get_results['qqbot_port']
        access_id = get_results['access_id']

        #qqbot_port = '8199'
        p_str1 = 'python '+ ABS_LOGIN_PATH + ' -i '+str(qqbot_port) + ' >> login'+str(qqbot_port)+'.txt'
        #qqbot_port = '8190'
        qqbot_num = qq_number
        qqbot_port = str(qqbot_port)
        qqbot_mc = access_id #'sirtgdmgwiivbegf'
        #qqbot_mc = 'worunhzbzyipdagc'
        # yuanlai >>>>>>>>>>>>8.20
        #p_str1 = 'python '+ ABS_LOGIN_PATH + ' -i '+qqbot_port + ' -o ' + qqbot_num + ' -m ' + qqbot_mc + ' >> login'+qqbot_port+'.txt'
        # xuanhui 8.20 把邮件发送到80217252
        p_str1 = 'python '+ ABS_LOGIN_PATH + ' -i '+qqbot_port + ' -o ' + '80617252' + ' -m ' + qqbot_mc + ' >> login'+qqbot_port+'.txt'
        #p_str1 = 'python '+ ABS_LOGIN_PATH + ' -i '+qqbot_port + ' -o ' + qqbot_num + ' -m ' + qqbot_mc
        command_str = 'python '+ ABS_LOGIN_PATH + ' -i '+qqbot_port + ' -o ' + qqbot_num + ' -m ' + qqbot_mc
        print 'p_str1:', p_str1
        print '========================================================================='
        p_str2 = 'pgrep -f ' + '"' + command_str + '"'
        print 'p_str2::',p_str2
        process_ids = subprocess.Popen(p_str2, \
                shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        process_id_list = process_ids.stdout.readlines()
        
        for process_id in process_id_list:
            process_id = process_id.strip()
            kill_str = 'kill -9 ' + process_id
            print 'kill_str::',kill_str
            p2 = subprocess.Popen(kill_str, \
                shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

        p2 = subprocess.Popen(p_str1, \
                shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        
        # # 存储qq端口、授权码等消息,用于后台主进程调用
        qq_info = dict()
        qq_info['qq_num'] = qqbot_num
        qq_info['qq_port'] = qqbot_port
        qq_info['access_id'] = qqbot_mc
        r.lpush(r_qq_receive_message,json.dumps(qq_info))
	    
        return True

    except:
        return False
Example #29
0
def homepage():
    ip = request.remote_addr
    timestamp = int(time.time())
    user_name = ''
    _id = current_user.get_id()
    cx = sqlite3.connect("/home/ubuntu8/yuanhuiru/xnr/xnr1/xnr/flask-admin.db")
    #cx = sqlite3.connect("sqlite:///flask-admin.db")
    cu=cx.cursor()
    users = cu.execute("select id,email from user") 
    for row in users:
        if row[0] == int(_id):
            user_name = row[1]
            break
    cx.close()


    current_date = ts2datetime(timestamp)
    current_time_new = datetime2ts(current_date)

    log_id = user_name +'_'+ current_date
    
    
    exist_item = es_xnr.exists(index=weibo_log_management_index_name,doc_type=weibo_log_management_index_type,\
        id=log_id)

    if exist_item:
        get_result = es_xnr.get(index=weibo_log_management_index_name,doc_type=weibo_log_management_index_type,\
        id=log_id)['_source']

        login_ip_list = get_result['login_ip']
        login_time_list = get_result['login_time']

        login_ip_list.append(ip)
        login_time_list.append(timestamp)

        es_xnr.update(index=weibo_log_management_index_name,doc_type=weibo_log_management_index_type,\
        id=log_id,body={'doc':{'login_ip':login_ip_list,'login_time':login_time_list}})
    else:
        item_dict = {}
        item_dict['user_name'] = user_name
        item_dict['login_ip'] = [ip]
        item_dict['login_time'] = [timestamp]
        item_dict['operate_date'] = current_date
        item_dict['operate_time'] = current_time_new
        item_dict['user_id'] = ''
        #item_dict['user_name'] = ''
        item_dict['operate_content'] = ''
        
        es_xnr.index(index=weibo_log_management_index_name,doc_type=weibo_log_management_index_type,\
            id=log_id,body=item_dict)

    return render_template('index/navigationMain.html')
Example #30
0
def get_my_group(xnr_user_no,groups):

    es_get_results = es_xnr.get(index=qq_xnr_index_name,doc_type=qq_xnr_index_type,id=xnr_user_no)['_source']

    qq_groups = es_get_results['qq_groups']
    my_group_list = {}
    for group_number in qq_groups:
        if group_number:
            try:
                my_group_list[group_number] = groups[group_number].strip()
            except:
                continue
    return my_group_list