Exemple #1
0
    def work(self):
        print 'start work.'
        timer = threading.Timer(self.wtime, self.work)
        self.thread.append(timer)
        timer.setDaemon(True)
        timer.start()

        print '**' * 50
        #return

        users = self.getuser()
        if len(users) < 1:
            return False
        ties = douban().get_topic()
        if len(ties) < 1:
            return False

        for i in ties:
            gurl = "http://www.douban.com/group/%s/" % i.get('gname')
            print '-' * 190
            print '开始发帖:%s      %s' % (i.get('d_id'), i.get('gname'))
            while True:
                user = random.choice(users)
                d = douban()
                if not d.login(user[0], user[1]):
                    del users[users.index(user)]
                    continue
                break
            #if not d.query_tie_first(i.get('d_id', ''), i.get('gname', '')):
            if douban().query_tie_first(i.get('d_id', '')):
                print 'http://www.douban.com/group/topic/%s 在小组:%s 首页,不回帖...' % (i.get('d_id', ''), i.get('gname', ''))
            else:
                print 'http://www.douban.com/group/topic/%s 不在小组:%s 首页,回帖...' % (i.get('d_id', ''), i.get('gname', ''))
                d.add_say(i.get('d_id', ''))
        print 'end work.'
def main():
    global SHARE_Q
    global MYSQL_CONNECTION
    global FILE_CONNECTION
    global DOUBAN_CONNECTION
    workers = []
    farmers = []
    # 向队列中放入任务, 真正使用时, 应该设置为可持续的放入任务

    # 建立Mysql连接
    MYSQL_CONNECTION = WCMysql('222.222.222.201', 'root', 'mao555hg', 'wechat')
    # File操作对象
    FILE_CONNECTION = WCFile()
    FILE_CONNECTION.set_dir('./public/image/')

    DOUBAN_CONNECTION = douban()

    # 开启farmer线程
    for i in range(_FARMER_THREAD_NUM):
        farmer_thread = WCThread(farmer)
        farmer_thread.start()
        farmers.append(farmer_thread)
    for farmer_thread in farmers:
        farmer_thread.join()
    # 开启worker线程
    for i in range(_WORKER_THREAD_NUM):
        worker_thread = WCThread(worker)
        worker_thread.start()  # 线程开始处理任务
        workers.append(worker_thread)
    for worker_thread in workers:
        worker_thread.join()
    # 等待所有任务完成
    SHARE_Q.join()
Exemple #3
0
 def add_user(self, num = 10000):
     s = 0
     if os.path.isfile(self.user_line):
         with file(self.user_line, 'r')as f:
             r = f.read().strip()
             try:
                 s = int(r)
             except ValueError:
                 s = 0
     users = csdn().query_user(s=s, e=num)
     print '一共 %s 个21cn.com 帐号' % len(users)
     #{'user':'******', 'pwd':'password', 'doubanname':'douban name'}
     for index, i in enumerate(users):
         dban = douban()
         print "尝试帐号:[ %s/%s | %s ]  %s  --  %s" %(index, len(users), i.get('id'), i.get('email').encode('utf8'), i.get('pwd').encode('utf8'))
         if dban.login(i.get('email').encode('utf8'), i.get('pwd').encode('utf8'), tuser=True):
             user = {'user':dban.user, 'pwd':dban.pwd, 'doubanname':dban.doubanname.decode('utf8').encode('utf8')}
             douban_db().add_user(user)
             dban.logout()
         with file(self.user_line, 'w')as f:
             f.write(str(int(i.get('id'))))
         #self.check403()
         print ''
         print "==" * 40
         print ''
Exemple #4
0
 def getuser(self):
     d = douban()
     d.query_user()
     users = []
     for i in d.users:
         user = i.get('user', '').encode('utf8')
         pwd = i.get('pwd', '').encode('utf8')
         users.append([user, pwd])
     return users
    def tie(self):
        global WORK, work
        state = [work, '暂停任务'] if work else [work, '开启任务']
        says="Hi,up this~~"
        turl=""
        dele = "hidden"
        add = "hidden"
        title = "任务管理"
        if self.tid > 0:
            says = douban().rw_says(self.tid, mode='r')
            turl = 'http://www.douban.com/group/topic/%s/' % self.tid
            dele = ""
            title = '修改任务'

        elif self.add:
            title = '新增任务'
            add = ""
        tie = {'tid':self.tid, 'add':self.add, 'action':'/tie?tid=%s&add=%s' % (self.tid, self.add), 'says':says, 'turl':turl, 'add': add, 'del': dele, 'title': title}
        self.render('./template/tie.tmp', tie=tie, work=state)
 def ch_tid(self, ct='add'):
     m = douban()
     code, self.tid = m.get_tid(self.url)
     if code == 200 and self.tid:
         m.rw_says(self.tid, says=self.says)
         "添加数据库"
         if ct == 'add':
             if m.add_topic(self.tid) > 0:
                 return '添加成功'
             else:
                 return '添加失败, 请确认是否已添加。'
         elif ct == 'upd':
             if m.update_topic(self.tid, self.says):
                 return '修改成功'
             else:
                 return '修改失败?'
     elif code == 302:
         return '网址输入错误,请检查网址是否输入正确'
     elif code == 403:
         return '没有权限,请检查帖子是否存在?'
     elif code == 404:
         return '网址不存在,请检查帖子是否存在'
 def ties(self):
     global WORK, work
     m = douban()
     ties = m.get_topic()
     dcode = {200: '正常', 403:'无权限', 404:'不存在'}
     for i in ties:
         i['Gname'] = m.get_group_name_ck(url="http://www.douban.com/group/%s/" % i.get('gname'), ftype=1)
         i['t_num'], code = m.get_say_num(tid=i.get('d_id'))
         new_say = m.get_new_says(i['mid'])
         i['cid'] = new_say.get('cid', "")
         i['user'] = new_say.get('user', "")
         i['dname'] = new_say.get('dname', "")
         ntime = str(new_say.get('rtime', ""))
         i['rtime'] = '---' if not len(ntime) else ntime
         i['url'] = 'http://www.douban.com/group/topic/%s' % i.get('d_id')
         i['scount'] = 0 if i['scount'] == None else i['scount']
         i['state'] = dcode.get(code)
         i['class'] = 'ok'
         if code != 200:
             i['class'] = 'error'
     #print ties
     state = [work, '暂停任务'] if work else [work, '开启任务']
     self.render('./template/ties.tmp', ties=ties, work=state)