使用方法
注册账号,过程略。网址:httPs://console.cloud.tencent.com/
进入云函数控制台的函数服务:https://console.cloud.tencent.com/scf/index?rid=1
单击“新建”
如图(BDUSS及Stoken获取见附录,粘贴代码时留下它原来的第一行
Python代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
from requests import session from hashlib import md5 from random import random from time import sleep class Tieba(): def __init__( self , BDUSS, STOKEN): self .BDUSS = BDUSS self .STOKEN = STOKEN self .count = [ 0 , 0 , 0 ] # 签到成功, 已经签到, 总 self .session = session() self .session.headers.update( { 'Accept' : 'text/html, */*; q=0.01' , 'Accept-Encoding' : 'gzip, deflate' , 'Accept-Language' : 'zh-CN,zh;q=0.9,en;q=0.8' , 'Connection' : 'keep-alive' , 'Referer' : 'http://tieba.baidu.com/i/i/forum' , 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/71.0.3578.98 Safari/537.36' , 'X-Requested-With' : 'XMLHttpRequest' } ) def set_cookie( self ): def fetch_tbs( self ): r = self .session.get( 'http://tieba.baidu.com/dc/common/tbs' ).json() if r[ 'is_login' ] = = 1 : self .tbs = r[ 'tbs' ] else : raise Exception( '获取tbs错误!以下为返回数据:' + str (r)) def fetch_likes( self ): self .rest = set () self .already = set () r = self .session.get( 'https://tieba.baidu.com/mo/q/newmoindex?' ).json() if r[ 'no' ] = = 0 : for forum in r[ 'data' ][ 'like_forum' ]: self .count[ 2 ] + = 1 if forum[ 'is_sign' ] = = 1 : self .already.add(forum[ 'forum_name' ]) else : self .rest.add(forum[ 'forum_name' ]) else : raise Exception( '获取关注贴吧错误!以下为返回数据:' + str (r)) def sign( self , forum_name): data = { 'kw' : forum_name, 'tbs' : self .tbs, 'sign' : md5(f 'kw={forum_name}tbs={self.tbs}tiebaclient!!!' .encode( 'utf8' )).hexdigest() } r = self .session.post( 'http://c.tieba.baidu.com/c/c/forum/sign' , data).json() if r[ 'error_code' ] = = '160002' : print (f '"{forum_name}"已签到!' ) self .count[ 1 ] + = 1 return True elif r[ 'error_code' ] = = '0' : print (f '"{forum_name}"签到成功,您是第{r["user_info"]["user_sign_rank"]}个签到的用户!' ) # Modify! self .count[ 0 ] + = 1 return True else : print (f '"{forum_name}"签到失败!以下为返回数据:{str(r)}' ) return False def loop( self , n): print (f '* 开始第{n}轮签到 *' ) rest = set () self .fetch_tbs() for forum_name in self .rest: sleep(random() * 3 ) flag = self .sign(forum_name) if not flag: rest.add(forum_name) self .rest = rest def main( self , max ): self .set_cookie() self .fetch_likes() n = 0 if self .already: print ( '* 已经签到的贴吧 *' ) for forum_name in self .already: print (f '"{forum_name}"已签到!' ) self .count[ 1 ] + = 1 while n < max and self .rest: n + = 1 self .loop(n) print ( '* 本日签到报告 *' ) print (f '共{self.count[2]}个贴吧,其中签到成功{self.count[0]}个,已经签到{self.count[1]}个,签到失败{len(self.rest)}个。' ) if self .rest: print ( '* 签到失败列表 *' ) for forum_name in self .rest: print (f '"{forum_name}"签到失败!' ) def main_handler( * args): with open ( 'BDUSS.txt' ) as f: BDUSS = f.read() with open ( 'STOKEN.txt' ) as f: STOKEN = f.read() task = Tieba(BDUSS, STOKEN) task.main( 3 ) # 不需要推送的删除以下几行 if task.rest: message = f '以下为未完成列表:' for forum in task.rest: message + = 'n' + forum data = { 'text' : '签到未完全完成!' , 'desp' : message} |
回到此界面,点击”测试”(应该会自动部署,如提示请先部署就先部署一下)
如若成功,应该能看到“测试成功”,输出签到的详细信息,可以进入下一步;如若失败,查看是否复制粘贴出错,无误仍出错请参照附录。
设置自动执行
表达式:0 0 1 * * * *
© 版权声明
文章版权归作者所有,未经允许请勿转载。