Ejemplo n.º 1
0
def operate_out_of_redis():

    while True:
        temp = r.rpop(operate_queue_name)
        #print 'temp.',temp
        if not temp:
            break

        queue_dict = json.loads(temp)

        channel = queue_dict['channel']
        operate_type = queue_dict['operate_type']

        task_detail = queue_dict['content']

        if channel == 'facebook':
            if operate_type == 'publish':
                try:
                    print 'task_detail..', task_detail
                    mark = get_submit_tweet_fb(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'retweet':
                try:
                    mark = get_retweet_operate_fb(task_detail)
                except Exception, e:
                    print e
                    # add_operate2redis(queue_dict)
            elif operate_type == 'comment':
                try:
                    mark = get_comment_operate_fb(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'like':
                try:
                    mark = get_like_operate_fb(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'at':
                try:
                    mark = get_at_operate_fb(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'private':
                try:
                    mark = get_private_operate_fb(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'add':
                try:
                    mark = get_add_friends(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'confirm':
                try:
                    mark = get_confirm_friends(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'delete':
                try:
                    mark = get_delete_friends(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

        elif channel == 'twitter':
            if operate_type == 'publish':
                try:
                    mark = get_submit_tweet_tw(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'retweet':
                try:
                    mark = get_retweet_operate_tw(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'comment':
                try:
                    mark = get_comment_operate_tw(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'like':
                try:
                    mark = get_like_operate_tw(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'at':
                try:
                    mark = get_at_operate_tw(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'private':
                try:
                    mark = get_private_operate_tw(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'follow':
                try:
                    mark = get_follow_operate_tw(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'unfollow':
                try:
                    mark = get_unfollow_operate_tw(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass
Ejemplo n.º 2
0
                            #add_operate2redis(queue_dict)
                            print 99999999999999, e
                            pass
                    break
                except:
                    continue

        elif channel == 'twitter':
            print '======================twitter===========================channel'
            if operate_type == 'publish':
                print '======================twitter===========================publish'
                try:
                    # add channel and operate_type
                    task_detail['channel'] = "twitter"
                    task_detail['operate_type'] = "publish"
                    mark = get_submit_tweet_tw(task_detail)

                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'retweet':
                try:
                    task_detail['channel'] = "twitter"
                    task_detail['operate_type'] = "retweet"
                    mark = get_retweet_operate_tw(task_detail)
                except:
                    #add_operate2redis(queue_dict)
                    pass

            elif operate_type == 'comment':
Ejemplo n.º 3
0
def publish_operate_timing():

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

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

                # try:
                #     p_url = result['p_url']
                # except:
                #     p_url = ''
                # try:
                #     rank = result['rank']
                # except:
                #     rank = u'0'
                # try:
                #     rankid = result['rankid']
                # except:
                #     rankid = ''
                #r_tid = result['tid']

                es_get_result = es_xnr.get(index=tw_xnr_index_name,
                                           doc_type=tw_xnr_index_type,
                                           id=xnr_user_no)['_source']
                print '=---------------'
                print es_get_result
                print '=---------------'
                tw_mail_account = es_get_result['tw_mail_account']
                tw_phone_account = es_get_result['tw_phone_account']
                password = es_get_result['password']

                if tw_mail_account:
                    account_name = tw_mail_account
                    print account_name
                elif tw_phone_account:
                    account_name = tw_phone_account
                else:
                    return False
                # kn 2019-6-27  push to aliyun
                try:
                    task_detail = {}
                    task_detail['channel'] = "twitter"
                    task_detail['operate_type'] = "publish"
                    task_detail['text'] = text
                    task_detail['tweet_type'] = tweet_type
                    task_detail['xnr_user_no'] = xnr_user_no
                    mark = get_submit_tweet_tw(task_detail)
                except Exception as e:
                    mark = 0
                    print e


# 2k19-6-27 之前的注销
# mark = tw_publish(account_name, password, text, tweet_type, xnr_user_no)
# 2019-6-27 之前的注销

                if mark:
                    #task_id = xnr_user_no + '_' + r_tid
                    task_id = _id
                    # item_exist = es_xnr.get(index=tw_xnr_retweet_timing_list_index_name,doc_type=\
                    #        tw_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=tw_xnr_timing_list_index_name,doc_type=\
                        tw_xnr_timing_list_index_type,id=task_id,body={'doc':item_exist})

            else:
                continue