Пример #1
0
def operate_out_of_redis():

	while True:
		print 1111
		while 1:
			count = 0
			try:
				print operate_queue_name
				temp = r.rpop(operate_queue_name)
				break
			except Exception, e:
				print e
				count += 1
				if count == 10:
					raise e
				else:
					continue
		print 2222
		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':
			while 1:
				try:
					if operate_type == 'publish':
						try:
							print '==========================================22222222222222222222222222222222222222222222222222facebookredis',task_detail
							# add channel and operate_type kn
							task_detail['channel'] = "facebook"
							task_detail['operate_type'] = "publish"
							print 'task_detail..',task_detail
							mark = get_submit_tweet_fb(task_detail)
						except Exception, e:
							#add_operate2redis(queue_dict)
							print 111111111111111, e
							print '111111111111111get submit_baocuo', e
							pass

					elif operate_type == 'retweet':
						try:
							task_detail['channel'] = "facebook"
							task_detail['operate_type'] = "retweet"
							mark = get_retweet_operate_fb(task_detail)
						except Exception,e:
							print 222222222222222, e
Пример #2
0
def add_operate2redis(item_dict):

    queue_dict = {}

    queue_dict['channel'] = item_dict['channel'] # weibo、facebook、twitter
    queue_dict['operate_type'] = item_dict['operate_type']  
    # publish-发帖、retweet-转发、comment-评论、like-点赞、follow-关注、unfollow-取消关注、at-提到、private-私信
    # add-发送添加好友请求、confirm-确认好友请求、delete-删除好友请求
    # receive - 回复

    queue_dict['content'] = item_dict['content']
    try:
        content = r_operate_queue.lpush(operate_queue_name,json.dumps(queue_dict))
        mark = True
    except:
        mark = False

    return mark
Пример #3
0
def add_operate2redis(item_dict):
    print 'add_operate2redis=============================='
    print item_dict
    queue_dict = {}
    queue_dict['channel'] = item_dict['channel'] # weibo、facebook、twitter
    queue_dict['operate_type'] = item_dict['operate_type']  
    # publish-发帖、retweet-转发、comment-评论、like-点赞、follow-关注、unfollow-取消关注、at-提到、private-私信
    # add-发送添加好友请求、confirm-确认好友请求、delete-删除好友请求
    # receive - 回复

    queue_dict['content'] = item_dict['content']
    while 1:
        try:
            content = r_operate_queue.lpush(operate_queue_name,json.dumps(queue_dict))
            print 'true=========================================='
            mark = True
            break
        except Exception as e:
            print 'false=========================================='
            print e
            #mark = False
            continue

    return mark
Пример #4
0

def add_operate2redis(item_dict):

    queue_dict = {}

    queue_dict['channel'] = item_dict['channel']  # weibo、facebook、twitter
    queue_dict['operate_type'] = item_dict['operate_type']
    # publish-发帖、retweet-转发、comment-评论、like-点赞、follow-关注、unfollow-取消关注、at-提到、private-私信
    # add-发送添加好友请求、confirm-确认好友请求、delete-删除好友请求
    # receive - 回复

    queue_dict['content'] = item_dict['content']
    try:
        content = r_operate_queue.lpush(operate_queue_name,
                                        json.dumps(queue_dict))
        mark = True
    except:
        mark = False

    return mark


if __name__ == '__main__':

    # save_to_fans_follow_ES('WXNR0004','1496814565','followers')
    #es_xnr.delete(index=weibo_xnr_fans_followers_index_name,doc_type=weibo_xnr_fans_followers_index_type,\
    #    id='AV4Zi0NasTFJ_K1Z2dDy')
    print r_operate_queue.lrange(operate_queue_name, 0, 8)
    # print r_operate_queue.rpop(operate_queue_name)
Пример #5
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
Пример #6
0
# -*-coding:utf-8-*-
import sys
import json
sys.path.append('../')
from global_utils import RE_QUEUE as re
from global_utils import R_OPERATE_QUEUE as r, operate_queue_name
# R_OPERATE_QUEUE = redis.StrictRedis(host=REDIS_HOST_45, port=REDIS_PORT_45, db=3)
# operate_queue_name = 'opetate'

#print re.lrange('params', 0, 10)
#print re.lrange('fb_tweet_params', 0, 10)
# 测试45redis上的队列
test_dict = {"test": "hello world"}
#r.lpush(operate_queue_name, json.dumps(test_dict))
#print r.lrange("operate", 0, 10)
print r.lrange(operate_queue_name, 0, 10)