示例#1
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 ''
示例#2
0
 def say(self, tid='54885639'):
     # http://www.douban.com/group/topic/54885639/?start=99999#last
     if not tid :
         print '帖子ID不正确.'
         return False
     url = 'http://www.douban.com/group/topic/%s/?start=99999999999#last' % tid
     con = str(self.req(url))
     if con == '403':
         print '非公开小组:http://www.douban.com/group/topic/%s/' % tid
         return False
     if con == '404':
         print '帖子不存在:http://www.douban.com/group/topic/%s/' % tid
         return False
     if con.find('只有小组成员才能发言') > 200:
         #group_name = re.findall('group-item.+?<a href="(.+?)".+?>', con, re.S)
         group_name = re.findall('group-item.+?<a href=".+?group/(.+?)/\?.+?".+?>', con, re.S)
         if len(group_name) > 0:
             group_name = group_name[0]
             if not self.join_group(group_name):
                 return False
             con = str(self.req(url))
         else:
             print '帖子找不到小组:http://www.douban.com/group/topic/%s/' % tid
     elif con.find('你已经申请加入小组,请等待小组管理员审核') > 200:
         print '你已经申请加入小组,请等待小组管理员审核'
         return False
     data = self.getfrom(con, 1)
     del data['sync_to_mb']
     list_say = self.choice_say(1, tid=tid)
     data['rv_comment'] = choice(list_say)
     url = 'http://www.douban.com/group/topic/%s/add_comment#last' % tid
     con = str(self.req(url, 'POST', data = data))
     i_say = self.get_i_say(con)
     data = {}
     #{'user_id': '1', 'cid':'say id', 'tid':'topic id', 'con': 'say what', 'rtime': '2014-07-31 18:33:00', 'state':1}
     data['user_id'] = douban_db().query_user(self.user)[0].get('id')
     data['cid'] = i_say[1]
     data['tid'] = tid
     data['con'] = i_say[0]
     data['rtime'] = i_say[3]
     data['state'] = '1'
     if not i_say:
         print '评论失败:[http://www.douban.com/group/topic/%s/]' % tid
         data['state'] = '0'
         douban_db().add_say(data)
         return False
     print '%s>评论内容保存在数据库,%s 行受影响' % ('-' * 150, douban_db().add_say(data))
     return True
示例#3
0
 def add_topic(self, tid):
     """{'user':'******', 'tid':'57533625', 'title':'标题1', 'con':'内容', 'group':'buybook', 'ctime':'2014-07-30 10:42:52', 'atime':'2014-07-31 16:29:05' }"""
     if not tid:
         return None
     con = str(self.req('http://www.douban.com/group/topic/%s/' % tid))
     data = {'tid': tid}
     data['group'] = re.findall('group-item.+?<a href=".+?group/(.+?)/\?.+?".+?>', con, re.S)[0].decode('utf8')
     data['title'] = [i.strip() for i in re.findall('<h1>(.+?)</h1>', con, re.S)][0].decode('utf8')
     data['user'], data['ctime'] = [i.decode('utf8') for i in re.findall('topic-doc.+?来自: .+?>(.+?)</a.+?color-green">(.+?)</span', con, re.S)[0]]
     data['con'] = BeautifulSoup(re.findall('(<div id="link-report".+?)<div class="sns-bar"', con, re.S)[0]).text.strip().encode('utf8').decode('utf8')
     data['atime'] = str(datetime.datetime.now())
     return douban_db().add_topic(data)
 def db(self):
     return mdb.douban_db()
示例#5
0
 def get_new_says(self, sid):
     info = douban_db().get_new_say(sid)
     if len(info) > 0:
         return info[0]
     else:return {}
示例#6
0
 def get_topic(self):
     return douban_db().get_topic()
示例#7
0
 def query_user(self, user=""):
     self.users = douban_db().query_user(user)
     return self.users
示例#8
0
 def del_user(self, user):
     if self.tuser: return None
     print "删除帐号:%s" % user
     return douban_db().del_user(user)
示例#9
0
 def alt_user(self, user):
     if self.tuser: return None
     print "%s 被禁用. 删除该帐号" % user
     return douban_db().alt_user(user)