增加浏览个人主页和加入圈子任务 (#61)

* add task

* add follow task

* fmt

* feat:fmt

* feat:sleep as util

* improve: delete meaningless sleep

Co-authored-by: wuhaitao <wuhaitao@bytedance.com>
Co-authored-by: 0-8-4 <ljd69154@liangjundi.cn>
This commit is contained in:
wu haitao 2022-11-02 12:12:37 +08:00 committed by GitHub
parent cfc5cecd05
commit c76ee156e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 24 deletions

7
.idea/.gitignore vendored
View File

@ -6,3 +6,10 @@
/dataSources.local.xml /dataSources.local.xml
# Editor-based HTTP Client requests # Editor-based HTTP Client requests
/httpRequests/ /httpRequests/
/inspectionProfiles/profiles_settings.xml
/inspectionProfiles/Project_Default.xml
/misc.xml
/miui-auto-tasks.iml
/modules.xml
/other.xml
/vcs.xml

View File

@ -3,11 +3,13 @@ import requests
import time import time
import json import json
import hashlib import hashlib
import random
from urllib import request from urllib import request
from http import cookiejar from http import cookiejar
from utils.utils import system_info, get_config, w_log, s_log, check_config, format_config from utils.utils import system_info, get_config, w_log, s_log, check_config, format_config, random_sleep, \
sleep_ten_sec_more
class MIUITask: class MIUITask:
@ -24,7 +26,7 @@ class MIUITask:
self.miui_vip_ph = '' self.miui_vip_ph = ''
# 签名 # 签名
def post_sign(self,data): def post_sign(self, data):
s_data = [] s_data = []
for d in data: for d in data:
s_data.append(str(d) + '=' + str(data[d])) s_data.append(str(d) + '=' + str(data[d]))
@ -81,7 +83,6 @@ class MIUITask:
w_log("取消点赞出错") w_log("取消点赞出错")
w_log(e) w_log(e)
def get_vip_cookie(self, url): def get_vip_cookie(self, url):
try: try:
@ -113,7 +114,8 @@ class MIUITask:
'action': 'BROWSE_POST_10S', 'action': 'BROWSE_POST_10S',
} }
try: try:
response = requests.get('https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByAction', params=params, headers=headers) response = requests.get('https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByAction',
params=params, headers=headers)
r_json = response.json() r_json = response.json()
if r_json['status'] == 401: if r_json['status'] == 401:
return w_log("浏览帖子失败Cookie无效") return w_log("浏览帖子失败Cookie无效")
@ -125,6 +127,66 @@ class MIUITask:
w_log("浏览帖子出错") w_log("浏览帖子出错")
w_log(e) w_log(e)
# 浏览个人主页10s
def browse_user_page(self):
headers = {
'cookie': str(self.cookie)
}
params = {
'userId': str(self.uid),
'action': 'BROWSE_SPECIAL_PAGES_USER_HOME',
}
try:
response = requests.get('https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByAction',
params=params, headers=headers)
r_json = response.json()
if r_json['status'] == 401:
return w_log("浏览个人主页失败Cookie无效")
elif r_json['status'] != 200:
return w_log("浏览个人主页完成,但有错误:" + str(r_json['message']))
score = r_json['entity']['score']
w_log("浏览个人主页完成,成长值+" + str(score))
except Exception as e:
w_log("浏览个人主页出错")
w_log(e)
# 加入小米圈子
def board_follow(self):
headers = {
'cookie': str(self.cookie)
}
try:
response = requests.get(
'https://api.vip.miui.com/api/community/board/follow?boardId=5462662&pathname=/mio/singleBoard&version=dev.1144',
headers=headers)
r_json = response.json()
if r_json['status'] == 401:
return w_log("加入小米圈子失败Cookie无效")
elif r_json['status'] != 200:
return w_log("加入小米圈子失败:" + str(r_json['message']))
w_log("加入小米圈子结果:" + str(r_json['message']))
except Exception as e:
w_log("加入小米圈子出错")
w_log(e)
# 退出小米圈子
def board_unfollow(self):
headers = {
'cookie': str(self.cookie)
}
try:
response = requests.get('https://api.vip.miui.com/api/community/board/unfollow?'
'boardId=5462662&pathname=/mio/singleBoard&version=dev.1144', headers=headers)
r_json = response.json()
if r_json['status'] == 401:
return w_log("退出小米圈子失败Cookie无效")
elif r_json['status'] != 200:
return w_log("退出小米圈子失败:" + str(r_json['message']))
w_log("退出小米圈子结果:" + str(r_json['message']))
except Exception as e:
w_log("退出小米圈子出错")
w_log(e)
# 社区拔萝卜 # 社区拔萝卜
def carrot_pull(self): def carrot_pull(self):
headers = { headers = {
@ -156,7 +218,9 @@ class MIUITask:
'cookie': str(self.cookie) 'cookie': str(self.cookie)
} }
try: try:
response = requests.get('https://api.vip.miui.com/mtop/planet/vip/user/checkin?pathname=/mio/checkIn&version=dev.1144', headers=headers) response = requests.get(
'https://api.vip.miui.com/mtop/planet/vip/user/checkin?pathname=/mio/checkIn&version=dev.1144',
headers=headers)
r_json = response.json() r_json = response.json()
if r_json['status'] == 401: if r_json['status'] == 401:
return w_log("社区成长值签到失败Cookie无效") return w_log("社区成长值签到失败Cookie无效")
@ -283,42 +347,45 @@ def process_exception(e: Exception):
def start(miui_task: MIUITask, check_in: bool, carrot_pull: bool): def start(miui_task: MIUITask, check_in: bool, carrot_pull: bool):
if miui_task.mi_login(): if miui_task.mi_login():
w_log("本脚本支持社区拔萝卜及成长值签到,因该功能存在风险默认禁用") w_log("本脚本支持社区拔萝卜及成长值签到,因该功能存在风险默认禁用")
w_log("如您愿意承担一切可能的后果,可编辑配置文件手动打开该功能") w_log("如您愿意承担一切可能的后果,可编辑配置文件手动打开该功能")
miui_task.login_app() miui_task.login_app()
if carrot_pull: if carrot_pull:
w_log("风险功能提示:正在进行社区拔萝卜") w_log("风险功能提示:正在进行社区拔萝卜")
time.sleep(0.5) random_sleep()
miui_task.carrot_pull() miui_task.carrot_pull()
if check_in: if check_in:
w_log("风险功能提示:正在进行成长值签到") w_log("风险功能提示:正在进行成长值签到")
time.sleep(0.5) random_sleep()
miui_task.check_in() miui_task.check_in()
w_log("正在完成浏览帖子10s任务第一次") w_log("正在完成浏览帖子10s任务第一次")
time.sleep(10.5) sleep_ten_sec_more()
miui_task.browse_post() miui_task.browse_post()
w_log("正在完成浏览帖子10s任务第二次") w_log("正在完成浏览帖子10s任务第二次")
time.sleep(10.5) sleep_ten_sec_more()
miui_task.browse_post() miui_task.browse_post()
w_log("正在完成浏览帖子10s任务第三次") w_log("正在完成浏览帖子10s任务第三次")
time.sleep(10.5) sleep_ten_sec_more()
miui_task.browse_post() miui_task.browse_post()
w_log("正在完成点赞任务") w_log("正在完成点赞任务")
miui_task.thumb_up() miui_task.thumb_up()
time.sleep(0.2) random_sleep()
miui_task.cancel_thumb_up() miui_task.cancel_thumb_up()
time.sleep(0.2) random_sleep()
miui_task.thumb_up() miui_task.thumb_up()
time.sleep(0.2) random_sleep()
miui_task.cancel_thumb_up() miui_task.cancel_thumb_up()
time.sleep(0.2) random_sleep()
miui_task.thumb_up() miui_task.thumb_up()
time.sleep(0.2) random_sleep()
miui_task.cancel_thumb_up() miui_task.cancel_thumb_up()
time.sleep(0.2) random_sleep()
miui_task.get_score() miui_task.board_unfollow()
random_sleep()
miui_task.board_follow()
random_sleep()
miui_task.browse_user_page()
def main(): def main():
@ -344,7 +411,7 @@ def main():
MIUITask(i.get('uid'), i.get('password'), i.get('user-agent'), device_id=i.get('device-id')), MIUITask(i.get('uid'), i.get('password'), i.get('user-agent'), device_id=i.get('device-id')),
i.get('check-in'), i.get('carrot-pull'), i.get('check-in'), i.get('carrot-pull'),
) )
time.sleep(5)
s_log(config.get('logging')) s_log(config.get('logging'))

View File

@ -1,4 +1,5 @@
import os import os
import random
import time import time
import platform import platform
import dotenv, yaml import dotenv, yaml
@ -130,3 +131,11 @@ def format_config(config: dict) -> dict:
else: else:
i['device-id'] = None i['device-id'] = None
return config return config
def random_sleep():
time.sleep(random.randint(1, 9))
def sleep_ten_sec_more():
time.sleep(random.randint(10, 12))