Skip to content

Commit c76ee15

Browse files
whtiswuhaitao0-8-4
authored
增加浏览个人主页和加入圈子任务 (0-8-4#61)
* add task * add follow task * fmt * feat:fmt * feat:sleep as util * improve: delete meaningless sleep Co-authored-by: wuhaitao <[email protected]> Co-authored-by: 0-8-4 <[email protected]>
1 parent cfc5cec commit c76ee15

File tree

3 files changed

+107
-24
lines changed

3 files changed

+107
-24
lines changed

.idea/.gitignore

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

miuitask.py

Lines changed: 91 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import time
44
import json
55
import hashlib
6+
import random
67

78
from urllib import request
89
from http import cookiejar
910

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
1113

1214

1315
class MIUITask:
@@ -22,9 +24,9 @@ def __init__(self, uid, password, user_agent, device_id):
2224
self.cookie = ''
2325
# 留空
2426
self.miui_vip_ph = ''
25-
27+
2628
# 签名
27-
def post_sign(self,data):
29+
def post_sign(self, data):
2830
s_data = []
2931
for d in data:
3032
s_data.append(str(d) + '=' + str(data[d]))
@@ -41,8 +43,8 @@ def thumb_up(self):
4143
'cookie': str(self.cookie)
4244
}
4345
sign_data = {
44-
'postId': '36625780',
45-
'timestamp': int(round(time.time() * 1000))
46+
'postId': '36625780',
47+
'timestamp': int(round(time.time() * 1000))
4648
}
4749
sign = self.post_sign(sign_data)
4850
data = {
@@ -52,7 +54,7 @@ def thumb_up(self):
5254
}
5355
try:
5456
response = requests.get('https://api.vip.miui.com/mtop/planet/vip/content/announceThumbUp', headers=headers,
55-
params=data)
57+
params=data)
5658
r_json = response.json()
5759
if r_json['code'] == 401:
5860
return w_log("点赞失败:Cookie无效")
@@ -81,7 +83,6 @@ def cancel_thumb_up(self):
8183
w_log("取消点赞出错")
8284
w_log(e)
8385

84-
8586
def get_vip_cookie(self, url):
8687

8788
try:
@@ -113,7 +114,8 @@ def browse_post(self):
113114
'action': 'BROWSE_POST_10S',
114115
}
115116
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)
117119
r_json = response.json()
118120
if r_json['status'] == 401:
119121
return w_log("浏览帖子失败:Cookie无效")
@@ -125,6 +127,66 @@ def browse_post(self):
125127
w_log("浏览帖子出错")
126128
w_log(e)
127129

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+
128190
# 社区拔萝卜
129191
def carrot_pull(self):
130192
headers = {
@@ -156,7 +218,9 @@ def check_in(self):
156218
'cookie': str(self.cookie)
157219
}
158220
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)
160224
r_json = response.json()
161225
if r_json['status'] == 401:
162226
return w_log("社区成长值签到失败:Cookie无效")
@@ -283,42 +347,45 @@ def process_exception(e: Exception):
283347

284348

285349
def start(miui_task: MIUITask, check_in: bool, carrot_pull: bool):
286-
287350
if miui_task.mi_login():
288351
w_log("本脚本支持社区拔萝卜及成长值签到,因该功能存在风险默认禁用")
289352
w_log("如您愿意承担一切可能的后果,可编辑配置文件手动打开该功能")
290353
miui_task.login_app()
291354
if carrot_pull:
292355
w_log("风险功能提示:正在进行社区拔萝卜")
293-
time.sleep(0.5)
356+
random_sleep()
294357
miui_task.carrot_pull()
295358
if check_in:
296359
w_log("风险功能提示:正在进行成长值签到")
297-
time.sleep(0.5)
360+
random_sleep()
298361
miui_task.check_in()
299362
w_log("正在完成浏览帖子10s任务,第一次")
300-
time.sleep(10.5)
363+
sleep_ten_sec_more()
301364
miui_task.browse_post()
302365
w_log("正在完成浏览帖子10s任务,第二次")
303-
time.sleep(10.5)
366+
sleep_ten_sec_more()
304367
miui_task.browse_post()
305368
w_log("正在完成浏览帖子10s任务,第三次")
306-
time.sleep(10.5)
369+
sleep_ten_sec_more()
307370
miui_task.browse_post()
308371
w_log("正在完成点赞任务")
309372
miui_task.thumb_up()
310-
time.sleep(0.2)
373+
random_sleep()
311374
miui_task.cancel_thumb_up()
312-
time.sleep(0.2)
375+
random_sleep()
313376
miui_task.thumb_up()
314-
time.sleep(0.2)
377+
random_sleep()
315378
miui_task.cancel_thumb_up()
316-
time.sleep(0.2)
379+
random_sleep()
317380
miui_task.thumb_up()
318-
time.sleep(0.2)
381+
random_sleep()
319382
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()
322389

323390

324391
def main():
@@ -329,7 +396,7 @@ def main():
329396
w_log("项目地址:https://github.com/0-8-4/miui-auto-tasks")
330397
w_log("欢迎 star,感谢東雲研究所中的大佬")
331398
w_log('---------- 配置检测 -------------')
332-
399+
333400
config = get_config()
334401

335402
if not check_config(config):
@@ -344,7 +411,7 @@ def main():
344411
MIUITask(i.get('uid'), i.get('password'), i.get('user-agent'), device_id=i.get('device-id')),
345412
i.get('check-in'), i.get('carrot-pull'),
346413
)
347-
414+
time.sleep(5)
348415
s_log(config.get('logging'))
349416

350417

utils/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import random
23
import time
34
import platform
45
import dotenv, yaml
@@ -130,3 +131,11 @@ def format_config(config: dict) -> dict:
130131
else:
131132
i['device-id'] = None
132133
return config
134+
135+
136+
def random_sleep():
137+
time.sleep(random.randint(1, 9))
138+
139+
140+
def sleep_ten_sec_more():
141+
time.sleep(random.randint(10, 12))

0 commit comments

Comments
 (0)