Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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']
    # add channel and operate_type kn
    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=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:
        # add params from 45 to aliyunn redis comment kn
        fb_tweet_params_dict = {}
        fb_tweet_params_dict["account_name"] = account_name
        fb_tweet_params_dict["password"] = password
        fb_tweet_params_dict["_id"] = _id
        fb_tweet_params_dict["uid"] = uid
        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_retweet(account_name, password, _id, uid, text, tweet_type,
                          xnr_user_no)
        #mark = fb_retweet('13520874771', '13018119931126731x', _id, uid, text, tweet_type, xnr_user_no)
    else:
        mark = False

    return mark
Esempio n. 4
0
def get_private_operate_fb(task_detail):

    xnr_user_no = task_detail['xnr_user_no']
    text = task_detail['text']
    uid = task_detail['uid']
    # add channel and operate_type kn
    channel = task_detail['channel']
    operate_type = task_detail['operate_type']

    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:
        # add params from 45 to aliyunn redis like kn
        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["uid"] = uid
        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_message(account_name, password, text, uid)
        #mark = fb_message('13520874771', '13018119931126731x', text, uid)
        print 'private!!'
    #mark = fb_message('8618348831412','Z1290605918',  text, uid)

    else:
        mark = False

    return mark
Esempio n. 5
0
def update_twitter_xnr_relations(root_uid,
                                 uid,
                                 data,
                                 update_portrait_info=False):
    # pingtaiguanzhu 决定了是否要在平台上真正关注该用户,涉及到更改该关系时,一定要指定该字段(1或0)。
    '''
    :param root_uid: xnr_uid
    :param uid: user_uid
    :param data: relation data. eg: data={'gensuiguanzhu': 1, 'pingtaiguanzhu': 1}
    :param update_portrait_info: update or not
    :return: update success or not
    '''
    xnr_user_no = tw_uid2xnr_user_no(root_uid)
    if xnr_user_no:
        data['platform'] = 'twitter'
        data['xnr_no'] = xnr_user_no
        data['xnr_uid'] = root_uid
        data['uid'] = uid
        '''
        pingtaiguanzhu = data.get('pingtaiguanzhu', -1)
        pingtaiguanzhu_state  = load_pingtaiguanzhu_state(root_uid, uid)
        if pingtaiguanzhu != pingtaiguanzhu_state:
            if pingtaiguanzhu == 1:
                'gaunzhu'
                data['pingtaiguanzhu'] = 1
            elif pingtaiguanzhu == 0:
                'quxiao'
                data['pingtaiguanzhu'] = 0
        '''
        # kn push jinrong cloud
        pingtaiguanzhu = data.get('pingtaiguanzhu', -1)
        pingtaiguanzhu_state = load_twitter_pingtaiguanzhu_state(root_uid, uid)
        tw_account, tw_password = load_twitter_user_passwd(root_uid)
        params_dict = {}
        params_dict['account'] = tw_account
        params_dict['password'] = tw_password
        params_dict['to_id'] = uid
        params_dict['xnr_user_no'] = xnr_user_no
        params_dict['root_uid'] = root_uid
        # 根据screen_name关注

        if pingtaiguanzhu != pingtaiguanzhu_state:
            if pingtaiguanzhu == 1:
                # 'gaunzhu'
                params_dict['operate_type'] = 'follow'
                data['pingtaiguanzhu'] = 1
                ali_re.lpush(twitter_relation_params, json.dumps(params_dict))
                print params_dict
                print "push aliyun successful"
            elif pingtaiguanzhu == 0:
                # 'quxiao'
                params_dict['operate_type'] = 'unfollow'
                data['pingtaiguanzhu'] = 0
                ali_re.lpush(twitter_relation_params, json.dumps(params_dict))
                print "push aliyun successful"
        else:
            #params_dict['operate_type'] = 'follow'
            #data['pingtaiguanzhu'] = 1
            #ali_re.lpush(twitter_relation_params, json.dumps(params_dict))
            #print "push aliyun successful"
            pass

        try:
            _id = '%s_%s' % (root_uid, uid)
            user_exist = es_xnr_2.exists(
                index=twitter_xnr_relations_index_name,
                doc_type=twitter_xnr_relations_index_type,
                id=_id)
            if user_exist:
                if update_portrait_info:
                    protrait_info = update_twitter_user_portrait_info(uid)
                    data.update(protrait_info)
                es_result = es_xnr_2.update(
                    index=twitter_xnr_relations_index_name,
                    doc_type=twitter_xnr_relations_index_type,
                    id=_id,
                    body={'doc': data})
            else:
                protrait_info = update_twitter_user_portrait_info(uid)
                data.update(protrait_info)
                es_result = es_xnr_2.index(
                    index=twitter_xnr_relations_index_name,
                    doc_type=twitter_xnr_relations_index_type,
                    id=_id,
                    body=data)
            return True
        except Exception, e:
            print 'update_twitter_xnr_relations Error: ', str(e)
Esempio n. 6
0
def publish_operate_timing():

    query_body = {
        'query':{
            'filtered':{
                'filter':{
                    'term':{'task_status':0}
                }
            }
        },
        'size':MAX_SEARCH_SIZE
    }

    results = es_xnr.search(index=fb_xnr_timing_list_index_name,doc_type=\
                    fb_xnr_timing_list_index_type,body=query_body)['hits']['hits']
    #print 'results::',results
    print 'results::',results
    if results:
        for result in results:
            print 'fb_retweet_in_time.publish_operate_timing'
            print result
            _id = result['_id']
            result = result['_source']
            xnr_user_no = result['xnr_user_no']
            if xnr_user_no == 'null':
                print xnr_user_no
                continue
            timestamp_set = result['post_time']
            print timestamp_set
            if timestamp_set <= int(time.time()):
				
                print 'timestamp, time.time()====================================================================='
                print timestamp_set, time.time()
                print '!!'
                text = result['text'].encode('utf-8')
                #tweet_type = task_source_ch2en[result['task_source']]
                tweet_type = result['task_source']

                print tweet_type

                # try:
                #     p_url = result['p_url']
                # except:
                #     p_url = ''
                # try:
                #     rank = result['rank']
                # except:
                #     rank = u'0'
                # try:
                #     rankid = result['rankid']
                # except:
                #     rankid = ''
                #r_fid = result['fid']
                print '==========================================', xnr_user_no

                es_get_result = es_xnr.get(index=fb_xnr_index_name,doc_type=fb_xnr_index_type,id=xnr_user_no)['_source']

                fb_mail_account = es_get_result['fb_mail_account']
                fb_phone_account = es_get_result['fb_phone_account']
                password = es_get_result['password']
                
                if fb_mail_account:
                    account_name = fb_mail_account
                elif fb_phone_account:
                    account_name = fb_phone_account
                else:
                    return False
                
                # add to aliyun redis about some fb_publish need params kn                       
                #mark = fb_publish(account_name, password, text, tweet_type, xnr_user_no)
                if account_name:
                    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
                        ali_re.lpush(FB_TWEET_PARAMS, json.dumps(fb_tweet_params_dict))
                        mark = True
                    except Exception as e:
                        print e
                else:
                    mark = False

                if mark:
                    #task_id = xnr_user_no + '_' + r_fid
                    task_id = _id
                    # item_exist = es_xnr.get(index=fb_xnr_retweet_timing_list_index_name,doc_type=\
                    #        fb_xnr_retweet_timing_list_index_type,id=task_id)['_source']
                    item_exist = {}
                    item_exist['task_status'] = 1
                    #item_exist['timstamp_post'] = int(time.time())

                    es_xnr.update(index=fb_xnr_timing_list_index_name,doc_type=\
                        fb_xnr_timing_list_index_type,id=task_id,body={'doc':item_exist})

            else:
                continue