def __init__(self): ''' use tornaod LogFormatter ''' self._news_url_template = string.Template( SITE_URL + "/index.php/News/student/p/$p/") self._init_going = False self.renren = RenRen() self.renren.login(config.renren_email, config.renren_pw) # login self.post_queue = [] # this is a heapq of new's id
def getBots(accounts): bots = [] for account in accounts: bot = RenRen() bot.login(account[0], account[1]) print bot.email, 'login' bots.append(bot) return bots
def getBots(accounts): if 'main.py' in sys.argv[0]: bots = [] for account in accounts: bot = RenRen() bot.login(account[0], account[1]) print bot.email, 'login' bots.append(bot) return bots else: r = redis.Redis(REDIS_HOST) bot = RenRen() bot._loginByCookie(r.get('xiaohuangji_cookies')) bot.email = '' if bot.token: return [bot] else: return []
# 主动聊天 import sys sys.path.append('..') import random from redis import Redis from renren import RenRen from my_accounts import accounts import time from crawl_info_config import crawl_info_list kv = Redis(host='localhost') account = accounts[0] bot = RenRen(account[0], account[1]) def handle(keyword, responses): statuses = bot.searchStatus(keyword, max_length=10) for status in statuses: user_id, status_id, status_time = status status_id_hash = int(str(status_id)[1:]) if not kv.getbit('status_record', status_id_hash): print keyword, user_id, status_id, status_time bot.addComment({ 'type': 'status', 'source_id': status_id, 'owner_id': user_id, 'message': random.choice(responses) })
# -*-coding:utf-8-*- ''' Created on 2013-5-21 @author: mush ''' from ntype import NTYPES import re from renren import RenRen # 匹配自己名字的正则@CityRun(601414776) self_match_pattern = re.compile('@烟台高校信息发布平台(\(601742726\))?') bot = RenRen() # 从一条消息里取出要表白的对象和要说的话 # 内容格式因为“@CityRun(601414776) 我想跟牟俊秋(340352870)表白:我喜欢你很久了!” def extractContent(message): content = self_match_pattern.sub('', message) #通过‘:’分割出表白对象和表白内容 content_s = content.split(') ', 1) #name = content_s[0].split('跟', 1)[-1].split('(',1)[0] #uid = content_s[0].split('跟', 1)[-1].split('(',1)[-1].split(')',1)[0] content = content_s[-1] #print 'name: '+name+' \tuid: '+uid+'\tcontent: '+content return content # 将不同类型的消息统一成同一种形式 def getNotiData(data):