3
3
import time
4
4
import json
5
5
import hashlib
6
+ import random
6
7
7
8
from urllib import request
8
9
from http import cookiejar
9
10
10
- from utils .utils import system_info , get_config , w_log , s_log , check_config , format_config
11
+ from utils .utils import system_info , get_config , w_log , s_log , check_config , format_config , random_sleep , \
12
+ sleep_ten_sec_more
11
13
12
14
13
15
class MIUITask :
@@ -22,9 +24,9 @@ def __init__(self, uid, password, user_agent, device_id):
22
24
self .cookie = ''
23
25
# 留空
24
26
self .miui_vip_ph = ''
25
-
27
+
26
28
# 签名
27
- def post_sign (self ,data ):
29
+ def post_sign (self , data ):
28
30
s_data = []
29
31
for d in data :
30
32
s_data .append (str (d ) + '=' + str (data [d ]))
@@ -41,8 +43,8 @@ def thumb_up(self):
41
43
'cookie' : str (self .cookie )
42
44
}
43
45
sign_data = {
44
- 'postId' : '36625780' ,
45
- 'timestamp' : int (round (time .time () * 1000 ))
46
+ 'postId' : '36625780' ,
47
+ 'timestamp' : int (round (time .time () * 1000 ))
46
48
}
47
49
sign = self .post_sign (sign_data )
48
50
data = {
@@ -52,7 +54,7 @@ def thumb_up(self):
52
54
}
53
55
try :
54
56
response = requests .get ('https://api.vip.miui.com/mtop/planet/vip/content/announceThumbUp' , headers = headers ,
55
- params = data )
57
+ params = data )
56
58
r_json = response .json ()
57
59
if r_json ['code' ] == 401 :
58
60
return w_log ("点赞失败:Cookie无效" )
@@ -81,7 +83,6 @@ def cancel_thumb_up(self):
81
83
w_log ("取消点赞出错" )
82
84
w_log (e )
83
85
84
-
85
86
def get_vip_cookie (self , url ):
86
87
87
88
try :
@@ -113,7 +114,8 @@ def browse_post(self):
113
114
'action' : 'BROWSE_POST_10S' ,
114
115
}
115
116
try :
116
- response = requests .get ('https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByAction' , params = params , headers = headers )
117
+ response = requests .get ('https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByAction' ,
118
+ params = params , headers = headers )
117
119
r_json = response .json ()
118
120
if r_json ['status' ] == 401 :
119
121
return w_log ("浏览帖子失败:Cookie无效" )
@@ -125,6 +127,66 @@ def browse_post(self):
125
127
w_log ("浏览帖子出错" )
126
128
w_log (e )
127
129
130
+ # 浏览个人主页10s
131
+ def browse_user_page (self ):
132
+ headers = {
133
+ 'cookie' : str (self .cookie )
134
+ }
135
+ params = {
136
+ 'userId' : str (self .uid ),
137
+ 'action' : 'BROWSE_SPECIAL_PAGES_USER_HOME' ,
138
+ }
139
+ try :
140
+ response = requests .get ('https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByAction' ,
141
+ params = params , headers = headers )
142
+ r_json = response .json ()
143
+ if r_json ['status' ] == 401 :
144
+ return w_log ("浏览个人主页失败:Cookie无效" )
145
+ elif r_json ['status' ] != 200 :
146
+ return w_log ("浏览个人主页完成,但有错误:" + str (r_json ['message' ]))
147
+ score = r_json ['entity' ]['score' ]
148
+ w_log ("浏览个人主页完成,成长值+" + str (score ))
149
+ except Exception as e :
150
+ w_log ("浏览个人主页出错" )
151
+ w_log (e )
152
+
153
+ # 加入小米圈子
154
+ def board_follow (self ):
155
+ headers = {
156
+ 'cookie' : str (self .cookie )
157
+ }
158
+ try :
159
+ response = requests .get (
160
+ 'https://api.vip.miui.com/api/community/board/follow?boardId=5462662&pathname=/mio/singleBoard&version=dev.1144' ,
161
+ headers = headers )
162
+ r_json = response .json ()
163
+ if r_json ['status' ] == 401 :
164
+ return w_log ("加入小米圈子失败:Cookie无效" )
165
+ elif r_json ['status' ] != 200 :
166
+ return w_log ("加入小米圈子失败:" + str (r_json ['message' ]))
167
+ w_log ("加入小米圈子结果:" + str (r_json ['message' ]))
168
+ except Exception as e :
169
+ w_log ("加入小米圈子出错" )
170
+ w_log (e )
171
+
172
+ # 退出小米圈子
173
+ def board_unfollow (self ):
174
+ headers = {
175
+ 'cookie' : str (self .cookie )
176
+ }
177
+ try :
178
+ response = requests .get ('https://api.vip.miui.com/api/community/board/unfollow?'
179
+ 'boardId=5462662&pathname=/mio/singleBoard&version=dev.1144' , headers = headers )
180
+ r_json = response .json ()
181
+ if r_json ['status' ] == 401 :
182
+ return w_log ("退出小米圈子失败:Cookie无效" )
183
+ elif r_json ['status' ] != 200 :
184
+ return w_log ("退出小米圈子失败:" + str (r_json ['message' ]))
185
+ w_log ("退出小米圈子结果:" + str (r_json ['message' ]))
186
+ except Exception as e :
187
+ w_log ("退出小米圈子出错" )
188
+ w_log (e )
189
+
128
190
# 社区拔萝卜
129
191
def carrot_pull (self ):
130
192
headers = {
@@ -156,7 +218,9 @@ def check_in(self):
156
218
'cookie' : str (self .cookie )
157
219
}
158
220
try :
159
- response = requests .get ('https://api.vip.miui.com/mtop/planet/vip/user/checkin?pathname=/mio/checkIn&version=dev.1144' , headers = headers )
221
+ response = requests .get (
222
+ 'https://api.vip.miui.com/mtop/planet/vip/user/checkin?pathname=/mio/checkIn&version=dev.1144' ,
223
+ headers = headers )
160
224
r_json = response .json ()
161
225
if r_json ['status' ] == 401 :
162
226
return w_log ("社区成长值签到失败:Cookie无效" )
@@ -283,42 +347,45 @@ def process_exception(e: Exception):
283
347
284
348
285
349
def start (miui_task : MIUITask , check_in : bool , carrot_pull : bool ):
286
-
287
350
if miui_task .mi_login ():
288
351
w_log ("本脚本支持社区拔萝卜及成长值签到,因该功能存在风险默认禁用" )
289
352
w_log ("如您愿意承担一切可能的后果,可编辑配置文件手动打开该功能" )
290
353
miui_task .login_app ()
291
354
if carrot_pull :
292
355
w_log ("风险功能提示:正在进行社区拔萝卜" )
293
- time . sleep ( 0.5 )
356
+ random_sleep ( )
294
357
miui_task .carrot_pull ()
295
358
if check_in :
296
359
w_log ("风险功能提示:正在进行成长值签到" )
297
- time . sleep ( 0.5 )
360
+ random_sleep ( )
298
361
miui_task .check_in ()
299
362
w_log ("正在完成浏览帖子10s任务,第一次" )
300
- time . sleep ( 10.5 )
363
+ sleep_ten_sec_more ( )
301
364
miui_task .browse_post ()
302
365
w_log ("正在完成浏览帖子10s任务,第二次" )
303
- time . sleep ( 10.5 )
366
+ sleep_ten_sec_more ( )
304
367
miui_task .browse_post ()
305
368
w_log ("正在完成浏览帖子10s任务,第三次" )
306
- time . sleep ( 10.5 )
369
+ sleep_ten_sec_more ( )
307
370
miui_task .browse_post ()
308
371
w_log ("正在完成点赞任务" )
309
372
miui_task .thumb_up ()
310
- time . sleep ( 0.2 )
373
+ random_sleep ( )
311
374
miui_task .cancel_thumb_up ()
312
- time . sleep ( 0.2 )
375
+ random_sleep ( )
313
376
miui_task .thumb_up ()
314
- time . sleep ( 0.2 )
377
+ random_sleep ( )
315
378
miui_task .cancel_thumb_up ()
316
- time . sleep ( 0.2 )
379
+ random_sleep ( )
317
380
miui_task .thumb_up ()
318
- time . sleep ( 0.2 )
381
+ random_sleep ( )
319
382
miui_task .cancel_thumb_up ()
320
- time .sleep (0.2 )
321
- miui_task .get_score ()
383
+ random_sleep ()
384
+ miui_task .board_unfollow ()
385
+ random_sleep ()
386
+ miui_task .board_follow ()
387
+ random_sleep ()
388
+ miui_task .browse_user_page ()
322
389
323
390
324
391
def main ():
@@ -329,7 +396,7 @@ def main():
329
396
w_log ("项目地址:https://github.com/0-8-4/miui-auto-tasks" )
330
397
w_log ("欢迎 star,感谢東雲研究所中的大佬" )
331
398
w_log ('---------- 配置检测 -------------' )
332
-
399
+
333
400
config = get_config ()
334
401
335
402
if not check_config (config ):
@@ -344,7 +411,7 @@ def main():
344
411
MIUITask (i .get ('uid' ), i .get ('password' ), i .get ('user-agent' ), device_id = i .get ('device-id' )),
345
412
i .get ('check-in' ), i .get ('carrot-pull' ),
346
413
)
347
-
414
+ time . sleep ( 5 )
348
415
s_log (config .get ('logging' ))
349
416
350
417
0 commit comments