From 79d631f25e810a1402666a3f36307a30f546c1c7 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Wed, 20 Apr 2022 13:00:29 +0800 Subject: [PATCH 01/45] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/push.ini.example | 8 +++++++- push.py | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/config/push.ini.example b/config/push.ini.example index f5cc758..c16a3ed 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -14,4 +14,10 @@ cqhttp_qq=10001 [telegram] api_url=api.telegram.org bot_token=123465:abcdefg -chat_id=123456 \ No newline at end of file +chat_id=123456 + +[wecom] +#企业微信的appid +agentid= +secret= +wechat_id= \ No newline at end of file diff --git a/push.py b/push.py index 70ff873..e105ae7 100644 --- a/push.py +++ b/push.py @@ -22,6 +22,7 @@ def title(status): return "「米游社脚本」执行失败!" +# telegram的推送 def telegram(status, push_message): http.post( url="https://{}/bot{}/sendMessage".format(cfg.get('telegram', 'api_url'), cfg.get('telegram', 'bot_token')), @@ -32,6 +33,7 @@ def telegram(status, push_message): ) +# server酱 def ftqq(status, push_message): http.post( url="https://sctapi.ftqq.com/{}.send".format(cfg.get('setting', 'push_token')), @@ -42,9 +44,10 @@ def ftqq(status, push_message): ) +# pushplus def pushplus(status, push_message): http.post( - url="http://www.pushplus.plus/send", + url="https://www.pushplus.plus/send", data={ "token": cfg.get('setting', 'push_token'), "title": title(status), @@ -53,6 +56,7 @@ def pushplus(status, push_message): ) +# cq http协议的推送 def cq_http(status, push_message): http.post( url=cfg.get('cqhttp', 'cqhttp_url'), @@ -63,20 +67,34 @@ def cq_http(status, push_message): ) +# 企业微信 感谢linjie5492@github +def wecom(status, push_message, wx_push_token=None): + secret = cfg.get('wecom', 'secret') + wechat_id = cfg.get('wecom', 'wechat_id') + push_token = http.post( + url=f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={wechat_id}&corpsecret={secret}', + data="").json()['access_token'] + push_data = { + "agentid": cfg.get('wecom', 'agentid'), + "msgtype": "text", + "touser": "@all", + "text": { + "content": title(status) + "\r\n" + push_message + }, "safe": 0} + http.post(f'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={push_token}', json=push_data) + + def push(status, push_message): if not load_config(): return 0 if cfg.getboolean('setting', 'enable'): push_server = cfg.get('setting', 'push_server').lower() log.info("正在执行推送......") - log.debug(f"推送所用的服务为:{push_server}") - if push_server == "cqhttp": - cq_http(status, push_message) - elif push_server == "ftqq": - ftqq(status, push_message) - elif push_server == "pushplus": - pushplus(status, push_message) - elif push_server == "telegram": - telegram(status, push_message) - log.info("推送完毕......") + try: + log.debug(f"推送所用的服务为:{push_server}") + eval(push_server[:10].lower() + "(status, push_message)") + except NameError: + log.warning("推送服务名称错误") + else: + log.info("推送完毕......") return 0 From 2030c9d1a167b4290f2ed19fb943b4506b1ebca3 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Wed, 20 Apr 2022 13:05:11 +0800 Subject: [PATCH 02/45] docker.py --- docker.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/docker.py b/docker.py index 28b2ea1..940a531 100644 --- a/docker.py +++ b/docker.py @@ -1,20 +1,12 @@ -import datetime import os -import logging -import signal import time -#from settings import * +import signal +import datetime +from loghelper import log from crontab import CronTab time_format = "%Y-%m-%d %H:%M:%S" -logging.basicConfig( - level=logging.INFO, - format='%(asctime)s %(levelname)s %(message)s', - datefmt='%Y-%m-%dT%H:%M:%S') - - -log = logging def stop_me(_signo, _stack): log.info("Docker container has stoped....") From 7d4059ad6ef4b5d7684574124e959b22dd09c9c0 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Wed, 20 Apr 2022 13:44:55 +0800 Subject: [PATCH 03/45] =?UTF-8?q?pushdeer=E6=94=AF=E6=8C=81(=E6=B5=8B?= =?UTF-8?q?=E8=AF=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/push.ini.example | 6 +++++- push.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/config/push.ini.example b/config/push.ini.example index c16a3ed..fc306dd 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -20,4 +20,8 @@ chat_id=123456 #企业微信的appid agentid= secret= -wechat_id= \ No newline at end of file +wechat_id= + +[pushdeer] +api_url=https://api2.pushdeer.com +token= \ No newline at end of file diff --git a/push.py b/push.py index e105ae7..cfc9c6f 100644 --- a/push.py +++ b/push.py @@ -68,7 +68,7 @@ def cq_http(status, push_message): # 企业微信 感谢linjie5492@github -def wecom(status, push_message, wx_push_token=None): +def wecom(status, push_message): secret = cfg.get('wecom', 'secret') wechat_id = cfg.get('wecom', 'wechat_id') push_token = http.post( @@ -84,6 +84,19 @@ def wecom(status, push_message, wx_push_token=None): http.post(f'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={push_token}', json=push_data) +# pushdeer +def pushdeer(status, push_message): + http.get( + url=f'{cfg.get("pushdeer", "api_url")}/message/push', + params={ + "push_key": cfg.get("pushdeer", "token"), + "text": title(status), + "desp": str(push_message).replace("\r\n", "\r\n\r\n"), + "type": "markdown" + } + ) + + def push(status, push_message): if not load_config(): return 0 From be36aa8148414040c9003a5ea364663b02b6a55a Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Wed, 20 Apr 2022 17:17:54 +0800 Subject: [PATCH 04/45] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d0bd5c4..bccaa64 100644 --- a/README.md +++ b/README.md @@ -60,21 +60,24 @@ 7. **此时Cookie已经复制到你的粘贴板上了** - ## 使用Docker运行 Docker的运行脚本基于Linux平台编写,暂未在Win平台测试。 将本项目Clone至本地后,请先按照上述步骤添加或修改配置文件。随后执行 -``` + +```text docker-compose up -d ``` + 启动docker容器。   容器运行成功后可用 -``` + +```text docker-compose logs -f ``` + 命令来查看程序输出。   若需要添加配置文件或修改配置文件,可直接在主机config文件夹中修改,修改的内容将实时同步在容器中。 @@ -93,7 +96,7 @@ docker-compose logs -f 4. 提交方法选`本地上传文件夹`,并在下方的函数代码处上传整个项目文件夹。 -5. 执行方法填写 `index.main_handler`. +5. 执行方法填写 `index.main_handler`,多用户请填写`main_handler_mulit`. 6. 展开高级配置,将执行超时时间修改为 `300 秒`,其他保持默认。 From accb15cb1a67b242ed8253f18a80e1cb7dd8d82c Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Thu, 21 Apr 2022 17:08:41 +0800 Subject: [PATCH 05/45] =?UTF-8?q?pushdeer=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- push.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/push.py b/push.py index cfc9c6f..6503a5f 100644 --- a/push.py +++ b/push.py @@ -89,7 +89,7 @@ def pushdeer(status, push_message): http.get( url=f'{cfg.get("pushdeer", "api_url")}/message/push', params={ - "push_key": cfg.get("pushdeer", "token"), + "pushkey": cfg.get("pushdeer", "token"), "text": title(status), "desp": str(push_message).replace("\r\n", "\r\n\r\n"), "type": "markdown" From 1e1f3459a58314acc687190d3966d8cba4d265c5 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sat, 23 Apr 2022 08:47:10 +0800 Subject: [PATCH 06/45] =?UTF-8?q?=E5=B4=A9=E5=9D=8F2=E6=8C=96=E5=9D=91&?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=87=8D=E5=A4=8D=E4=BB=A3=E7=A0=81&?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=98=E9=87=8F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account.py | 44 +++++++++++++++++++++++++++++++++++++++++++ config.py | 12 +++--------- genshin.py | 27 +++++++------------------- honkai2.py | 32 +++++++++++++++++++++++++++++++ honkai3rd.py | 25 +++++-------------------- login.py | 4 ++-- mihoyobbs.py | 14 +++++++------- setting.py | 53 ++++++++++++++++++++++++++++++++++------------------ 8 files changed, 135 insertions(+), 76 deletions(-) create mode 100644 account.py create mode 100644 honkai2.py diff --git a/account.py b/account.py new file mode 100644 index 0000000..7d6d031 --- /dev/null +++ b/account.py @@ -0,0 +1,44 @@ +import config +import setting +from request import http +from loghelper import log +from error import CookieError + + +def game_id2name(game_id: str) -> str: + try: + return setting.game_id2name[game_id] + except NameError: + return game_id + + +def stop_module(game_id: str) -> None: + if game_id == "bh2_cn": + # config.honkai2rd_Auto_sign = False + # 崩坏2功能敬请期待 + pass + elif game_id == "bh3_cn": + config.honkai3rd_Auto_sign = False + elif game_id == "nxx_cn": + # 未定好像没米游社签到 + pass + elif game_id == "hk4e_cn": + config.genshin_Auto_sign = False + else: + raise NameError + config.save_config() + + +def get_account_list(game_id: str, headers: dict) -> list: + log.info(f"正在获取米哈游账号绑定的{game_id2name(game_id)}账号列表...") + temp_list = [] + req = http.get(setting.account_Info_url + game_id, headers=headers) + data = req.json() + if data["retcode"] != 0: + log.warning(f"获取{game_id2name(game_id)}账号列表失败!") + stop_module(game_id) + raise CookieError("BBS Cookie Error") + for i in data["data"]["list"]: + temp_list.append([i["nickname"], i["game_uid"], i["region"]]) + log.info(f"已获取到{len(temp_list)}个{game_id2name(game_id)}账号信息") + return temp_list diff --git a/config.py b/config.py index 11fd72c..c9ab67d 100644 --- a/config.py +++ b/config.py @@ -22,7 +22,7 @@ mihoyobbs = { # 1是崩坏3 2是原神 3是崩坏2 4是未定事件簿 5是大别墅 # 可以通过设置讨论区的id位置来设置主讨论区,[5,1]就是大别墅为主社区 # 看帖子 点赞 分享帖子都是使用主社区获取到的列表 - "bbs_Signin_multi_list": [2, 5], + "bbs_Signin_multi_list": [], # 浏览3个帖子 "bbs_Read_posts": True, # 完成5次点赞 @@ -57,14 +57,7 @@ def load_config(): mihoyobbs_Stuid = data["mihoyobbs_Stuid"] mihoyobbs_Stoken = data["mihoyobbs_Stoken"] mihoyobbs_Cookies = data["mihoyobbs_Cookies"] - mihoyobbs["bbs_Global"] = data["mihoyobbs"]["bbs_Global"] - mihoyobbs["bbs_Signin"] = data["mihoyobbs"]["bbs_Signin"] - mihoyobbs["bbs_Signin_multi"] = data["mihoyobbs"]["bbs_Signin_multi"] - mihoyobbs["bbs_Signin_multi_list"] = data["mihoyobbs"]["bbs_Signin_multi_list"] - mihoyobbs["bbs_Read_posts"] = data["mihoyobbs"]["bbs_Read_posts"] - mihoyobbs["bbs_Like_posts"] = data["mihoyobbs"]["bbs_Like_posts"] - mihoyobbs["bbs_Unlike"] = data["mihoyobbs"]["bbs_Unlike"] - mihoyobbs["bbs_Share"] = data["mihoyobbs"]["bbs_Share"] + mihoyobbs = data["mihoyobbs"] genshin_Auto_sign = data["genshin_Auto_sign"] honkai3rd_Auto_sign = data["honkai3rd_Auto_sign"] f.close() @@ -101,3 +94,4 @@ def clear_cookies(): f.flush() f.close() log.info("Cookie删除完毕") + diff --git a/genshin.py b/genshin.py index 21afe58..dedce53 100644 --- a/genshin.py +++ b/genshin.py @@ -6,6 +6,7 @@ import setting from request import http from loghelper import log from error import CookieError +from account import get_account_list class Genshin: @@ -15,35 +16,21 @@ class Genshin: 'DS': tools.get_ds(web=True, web_old=True), 'Origin': 'https://webstatic.mihoyo.com', 'x-rpc-app_version': setting.mihoyobbs_Version_old, - 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0', + 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0', 'x-rpc-client_type': setting.mihoyobbs_Client_type_web, - 'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true&act_id=e202009291139501&utm_source=bbs&utm_medium=mys&utm_campaign=icon', + 'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true&act_id' + f'={setting.genshin_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,en-US;q=0.8', 'X-Requested-With': 'com.mihoyo.hyperion', "Cookie": config.mihoyobbs_Cookies, 'x-rpc-device_id': tools.get_device_id() } - self.acc_List = self.get_account_list() + self.acc_List = get_account_list("hk4e_cn", self.headers) if len(self.acc_List) != 0: self.sign_Give = self.get_signgive() - # 获取绑定的账号列表 - def get_account_list(self) -> list: - log.info("正在获取米哈游账号绑定原神账号列表...") - temp_list = [] - req = http.get(setting.genshin_Account_info_url, headers=self.headers) - data = req.json() - if data["retcode"] != 0: - log.warning("获取账号列表失败!") - config.genshin_Auto_sign = False - config.save_config() - raise CookieError("BBS Cookie Errror") - for i in data["data"]["list"]: - temp_list.append([i["nickname"], i["game_uid"], i["region"]]) - log.info(f"已获取到{len(temp_list)}个原神账号信息") - return temp_list - # 获取已经签到奖励列表 def get_signgive(self) -> list: log.info("正在获取签到奖励列表...") @@ -68,7 +55,7 @@ class Genshin: # 签到 def sign_account(self): - return_data = "原神:" + return_data = "原神: " if len(self.acc_List) != 0: for i in self.acc_List: log.info(f"正在为旅行者{i[0]}进行签到...") diff --git a/honkai2.py b/honkai2.py new file mode 100644 index 0000000..aefa515 --- /dev/null +++ b/honkai2.py @@ -0,0 +1,32 @@ +import time +import tools +import config +import random +import setting +from request import http +from loghelper import log +from error import CookieError +from account import get_account_list + + +class Honkai2: + def __init__(self) -> None: + self.headers = { + 'Accept': 'application/json, text/plain, */*', + 'DS': tools.get_ds(web=True, web_old=True), + 'Origin': 'https://webstatic.mihoyo.com', + 'x-rpc-app_version': setting.mihoyobbs_Version_old, + 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0', + 'x-rpc-client_type': setting.mihoyobbs_Client_type_web, + 'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin/bh2/index.html?bbs_auth_required=true&' + f'act_id={setting.honkai2_Act_id}&bbs_presentation_style=fullscreen&utm_source=bbs&' + 'utm_medium=mys&utm_campaign=icon', + 'Accept-Encoding': 'gzip, deflate', + 'Accept-Language': 'zh-CN,en-US;q=0.8', + 'X-Requested-With': 'com.mihoyo.hyperion', + "Cookie": config.mihoyobbs_Cookies, + 'x-rpc-device_id': tools.get_device_id() + } + self.acc_List = get_account_list("bh2_cn", self.headers) + self.sign_day = 0 diff --git a/honkai3rd.py b/honkai3rd.py index 3c75c9b..09aba9a 100644 --- a/honkai3rd.py +++ b/honkai3rd.py @@ -5,7 +5,7 @@ import random import setting from request import http from loghelper import log -from error import CookieError +from account import get_account_list class Honkai3rd: @@ -27,25 +27,9 @@ class Honkai3rd: "Cookie": config.mihoyobbs_Cookies, 'x-rpc-device_id': tools.get_device_id() } - self.acc_List = self.get_account_list() + self.acc_List = get_account_list("bh3_cn", self.headers) self.sign_day = 0 - # 获取绑定的账号列表 - def get_account_list(self) -> list: - log.info("正在获取米哈游账号绑定的崩坏3账号列表...") - temp_list = [] - req = http.get(setting.honkai3rd_Account_info_url, headers=self.headers) - data = req.json() - if data["retcode"] != 0: - log.warning("获取账号列表失败!") - config.honkai3rd_Auto_sign = False - config.save_config() - raise CookieError("BBS Cookie Error") - for i in data["data"]["list"]: - temp_list.append([i["nickname"], i["game_uid"], i["region"]]) - log.info(f"已获取到{len(temp_list)}个崩坏3账号信息") - return temp_list - # 获取今天已经签到了的dict def get_today_item(self, raw_data: list): # 用range进行循环,当status等于0的时候上一个就是今天签到的dict @@ -61,14 +45,15 @@ class Honkai3rd: # 签到 def sign_account(self): - return_data = "崩坏3:" + return_data = "崩坏3: " if len(self.acc_List) == 0: log.warning("账号没有绑定任何崩坏3账号!") return_data += "\n并没有绑定任何崩坏3账号" else: for i in self.acc_List: log.info(f"正在为舰长 {i[0]} 进行签到...") - req = http.get(setting.honkai3rd_Is_signurl.format(setting.honkai3rd_Act_id, i[2], i[1]), headers=self.headers) + req = http.get(setting.honkai3rd_Is_signurl.format(setting.honkai3rd_Act_id, i[2], i[1]), + headers=self.headers) data = req.json() re_message = "" if data["retcode"] != 0: diff --git a/login.py b/login.py index fa0955f..57034d4 100644 --- a/login.py +++ b/login.py @@ -18,10 +18,10 @@ def login(): config.mihoyobbs_Login_ticket = i.split("=")[1] break # 这里获取Stuid,但是实际是可以直接拿cookie里面的Uid - data = request.get(url=setting.bbs_Cookieurl.format(config.mihoyobbs_Login_ticket)) + data = request.get(url=setting.bbs_Cookie_url.format(config.mihoyobbs_Login_ticket)) if "成功" in data["data"]["msg"]: config.mihoyobbs_Stuid = str(data["data"]["cookie_info"]["account_id"]) - data = request.get(url=setting.bbs_Cookieurl2.format(config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid)) + data = request.get(url=setting.bbs_Cookie_url2.format(config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid)) config.mihoyobbs_Stoken = data["data"]["list"][0]["token"] log.info("登录成功!") log.info("正在保存Config!") diff --git a/mihoyobbs.py b/mihoyobbs.py index 5e31eed..bc2205b 100644 --- a/mihoyobbs.py +++ b/mihoyobbs.py @@ -50,7 +50,7 @@ class mihoyobbs: global Today_have_getcoins global Have_coins log.info("正在获取任务列表") - req = http.get(url=setting.bbs_Taskslist, headers=self.headers) + req = http.get(url=setting.bbs_Tasks_list, headers=self.headers) data = req.json() if "err" in data["message"] or data["retcode"] == -100: log.error("获取任务列表失败,你的cookie可能已过期,请重新设置cookie。") @@ -101,7 +101,7 @@ class mihoyobbs: def get_list(self) -> list: temp_list = [] log.info("正在获取帖子列表......") - req = http.get(url=setting.bbs_Listurl.format(setting.mihoyobbs_List_Use[0]["forumId"]), headers=self.headers) + req = http.get(url=setting.bbs_List_url.format(setting.mihoyobbs_List_Use[0]["forumId"]), headers=self.headers) data = req.json() for n in range(5): temp_list.append([data["data"]["list"][n]["post"]["post_id"], data["data"]["list"][n]["post"]["subject"]]) @@ -115,7 +115,7 @@ class mihoyobbs: else: log.info("正在签到......") for i in setting.mihoyobbs_List_Use: - req = http.post(url=setting.bbs_Signurl.format(i["id"]), data={}, headers=self.headers) + req = http.post(url=setting.bbs_Sign_url.format(i["id"]), data={}, headers=self.headers) data = req.json() if "err" not in data["message"]: log.info(str(i["name"] + data["message"])) @@ -132,7 +132,7 @@ class mihoyobbs: else: log.info("正在看帖......") for i in range(self.Task_do["bbs_Read_posts_num"]): - req = http.get(url=setting.bbs_Detailurl.format(self.postsList[i][0]), headers=self.headers) + req = http.get(url=setting.bbs_Detail_url.format(self.postsList[i][0]), headers=self.headers) data = req.json() if data["message"] == "OK": log.debug("看帖:{} 成功".format(self.postsList[i][1])) @@ -145,7 +145,7 @@ class mihoyobbs: else: log.info("正在点赞......") for i in range(self.Task_do["bbs_Like_posts_num"]): - req = http.post(url=setting.bbs_Likeurl, headers=self.headers, + req = http.post(url=setting.bbs_Like_url, headers=self.headers, json={"post_id": self.postsList[i][0], "is_cancel": False}) data = req.json() if data["message"] == "OK": @@ -153,7 +153,7 @@ class mihoyobbs: # 判断取消点赞是否打开 if config.mihoyobbs["bbs_Unlike"]: time.sleep(random.randint(2, 8)) - req = http.post(url=setting.bbs_Likeurl, headers=self.headers, + req = http.post(url=setting.bbs_Like_url, headers=self.headers, json={"post_id": self.postsList[i][0], "is_cancel": True}) data = req.json() if data["message"] == "OK": @@ -168,7 +168,7 @@ class mihoyobbs: else: log.info("正在执行分享任务......") for i in range(3): - req = http.get(url=setting.bbs_Shareurl.format(self.postsList[0][0]), headers=self.headers) + req = http.get(url=setting.bbs_Share_url.format(self.postsList[0][0]), headers=self.headers) data = req.json() if data["message"] == "OK": log.debug("分享:{} 成功".format(self.postsList[0][1])) diff --git a/setting.py b/setting.py index f2c438e..0017246 100644 --- a/setting.py +++ b/setting.py @@ -41,28 +41,45 @@ mihoyobbs_List = [{ "url": "https://bbs.mihoyo.com/sr/" }] +game_id2name = { + "bh2_cn": "崩坏2", + "bh3_cn": "崩坏3", + "nxx_cn": "未定事件簿", + "hk4e_cn": "原神", +} # Config Load之后run里面进行列表的选择 mihoyobbs_List_Use = [] -# 米游社的API列表 -bbs_Cookieurl = "https://webapi.account.mihoyo.com/Api/cookie_accountinfo_by_loginticket?login_ticket={}" -bbs_Cookieurl2 = "https://api-takumi.mihoyo.com/auth/api/getMultiTokenByLoginTicket?login_ticket={}&token_types=3&uid={}" -bbs_Taskslist = "https://bbs-api.mihoyo.com/apihub/sapi/getUserMissionsState" # 获取任务列表 -bbs_Signurl = "https://bbs-api.mihoyo.com/apihub/sapi/signIn?gids={}" # post -bbs_Listurl = "https://bbs-api.mihoyo.com/post/api/getForumPostList?forum_id={}&is_good=false&is_hot=false&page_size=20&sort_type=1" -bbs_Detailurl = "https://bbs-api.mihoyo.com/post/api/getPostFull?post_id={}" -bbs_Shareurl = "https://bbs-api.mihoyo.com/apihub/api/getShareConf?entity_id={}&entity_type=1" -bbs_Likeurl = "https://bbs-api.mihoyo.com/apihub/sapi/upvotePost" # post json +# 通用设置 +bbs_Api = "https://bbs-api.mihoyo.com" +web_Api = "https://api-takumi.mihoyo.com" +account_Info_url = web_Api + "/binding/api/getUserGameRolesByCookie?game_biz=" -# 原神自动签到相关的设置 -genshin_Act_id = "e202009291139501" -genshin_Account_info_url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=hk4e_cn" -genshin_Signlisturl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/home?act_id={}" -genshin_Is_signurl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/info?act_id={}®ion={}&uid={}" -genshin_Signurl = "https://api-takumi.mihoyo.com/event/bbs_sign_reward/sign" +# 米游社的API列表 +bbs_Cookie_url = "https://webapi.account.mihoyo.com/Api/cookie_accountinfo_by_loginticket?login_ticket={}" +bbs_Cookie_url2 = web_Api + "/auth/api/getMultiTokenByLoginTicket?login_ticket={}&token_types=3&uid={}" +bbs_Tasks_list = bbs_Api + "/apihub/sapi/getUserMissionsState" # 获取任务列表 +bbs_Sign_url = bbs_Api + "/apihub/sapi/signIn?gids={}" # post +bbs_List_url = bbs_Api + "/post/api/getForumPostList?forum_id={}&is_good=false&is_hot=false&page_size=20&sort_type=1" +bbs_Detail_url = bbs_Api + "/post/api/getPostFull?post_id={}" +bbs_Share_url = bbs_Api + "/apihub/api/getShareConf?entity_id={}&entity_type=1" +bbs_Like_url = bbs_Api + "/apihub/sapi/upvotePost" # post json + +# 崩坏2自动签到相关的相关设置 +honkai2_Act_id = "e202203291431091" +honkai2_Account_info_url = account_Info_url + "bh2_cn" # 废弃字段,之后可能会删除 +honkai2_Is_signurl = web_Api + "/event/luna/info?lang=zh-cn&act_id={}®ion={}&uid={}" +honkai2_Sign_url = web_Api + "/event/luna/sign" # 崩坏3自动签到相关的设置 honkai3rd_Act_id = "ea20211026151532" -honkai3rd_Account_info_url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=bh3_cn" -honkai3rd_Is_signurl = "https://api-takumi.mihoyo.com/common/eutheniav2/index?act_id={}®ion={}&uid={}" -honkai3rd_SignUrl = "https://api-takumi.mihoyo.com/common/eutheniav2/sign" +honkai3rd_Account_info_url = account_Info_url + "bh3_cn" # 废弃字段,之后可能会删除 +honkai3rd_Is_signurl = web_Api + "/common/eutheniav2/index?act_id={}®ion={}&uid={}" +honkai3rd_SignUrl = web_Api + "/common/eutheniav2/sign" + +# 原神自动签到相关的设置 +genshin_Act_id = "e202009291139501" +genshin_Account_info_url = account_Info_url + "hk4e_cn" # 废弃字段,之后可能会删除 +genshin_Signlisturl = web_Api + "/event/bbs_sign_reward/home?act_id={}" +genshin_Is_signurl = web_Api + "/event/bbs_sign_reward/info?act_id={}®ion={}&uid={}" +genshin_Signurl = web_Api + "/event/bbs_sign_reward/sign" From 25cc35461c206ac568642400c96ceea4a296da23 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sat, 23 Apr 2022 09:35:26 +0800 Subject: [PATCH 07/45] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 41 +++++++++++++++++++++++------------------ mihoyobbs.py | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/main.py b/main.py index 68d2dbc..0a4506e 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ from error import CookieError def main(): # 初始化,加载配置 - return_data = "\n米游社:" + return_data = "\n米游社: " config.load_config() if config.enable_Config: # 检测参数是否齐全,如果缺少就进行登入操作 @@ -36,26 +36,31 @@ def main(): setting.mihoyobbs_List_Use.append(i) # 米游社签到 if config.mihoyobbs["bbs_Global"]: - bbs = mihoyobbs.mihoyobbs() + bbs = mihoyobbs.Mihoyobbs() if bbs.Task_do["bbs_Sign"] and bbs.Task_do["bbs_Read_posts"] and bbs.Task_do["bbs_Like_posts"] and \ bbs.Task_do["bbs_Share"]: - return_data += "\n" + f"今天已经全部完成了!\n"\ - f"一共获得{mihoyobbs.Today_have_getcoins}个米游币\n目前有{mihoyobbs.Have_coins}个米游币" - log.info(f"今天已经全部完成了!一共获得{mihoyobbs.Today_have_getcoins}个米游币,目前有{mihoyobbs.Have_coins}个米游币") + return_data += "\n" + f"今天已经全部完成了!\n" \ + f"一共获得{mihoyobbs.today_have_get_coins}个米游币\n目前有{mihoyobbs.Have_coins}个米游币" + log.info(f"今天已经全部完成了!一共获得{mihoyobbs.today_have_get_coins}个米游币,目前有{mihoyobbs.Have_coins}个米游币") else: - if config.mihoyobbs["bbs_Signin"]: - bbs.signing() - if config.mihoyobbs["bbs_Read_posts"]: - bbs.read_posts() - if config.mihoyobbs["bbs_Like_posts"]: - bbs.Likeposts() - if config.mihoyobbs["bbs_Share"]: - bbs.share_post() - bbs.Get_taskslist() - return_data += "\n" + f"今天已经获得{mihoyobbs.Today_have_getcoins}个米游币\n"\ - f"还能获得{mihoyobbs.Today_getcoins}个米游币\n目前有{mihoyobbs.Have_coins}个米游币" - log.info(f"今天已经获得{mihoyobbs.Today_have_getcoins}个米游币," - f"还能获得{mihoyobbs.Today_getcoins}个米游币,目前有{mihoyobbs.Have_coins}个米游币") + i = 0 + while mihoyobbs.today_get_coins != 0 and i < 3: + if i > 0: + bbs.refresh_list() + if config.mihoyobbs["bbs_Signin"]: + bbs.signing() + if config.mihoyobbs["bbs_Read_posts"]: + bbs.read_posts() + if config.mihoyobbs["bbs_Like_posts"]: + bbs.like_posts() + if config.mihoyobbs["bbs_Share"]: + bbs.share_post() + bbs.get_tasks_list() + i += 1 + return_data += "\n" + f"今天已经获得{mihoyobbs.today_have_get_coins}个米游币\n" \ + f"还能获得{mihoyobbs.today_get_coins}个米游币\n目前有{mihoyobbs.Have_coins}个米游币" + log.info(f"今天已经获得{mihoyobbs.today_have_get_coins}个米游币," + f"还能获得{mihoyobbs.today_get_coins}个米游币,目前有{mihoyobbs.Have_coins}个米游币") time.sleep(random.randint(2, 8)) else: return_data += "\n" + "米游社功能未启用!" diff --git a/mihoyobbs.py b/mihoyobbs.py index bc2205b..8e8d38b 100644 --- a/mihoyobbs.py +++ b/mihoyobbs.py @@ -7,13 +7,12 @@ from request import http from loghelper import log from error import CookieError - -Today_getcoins = 0 -Today_have_getcoins = 0 # 这个变量以后可能会用上,先留着了 +today_get_coins = 0 +today_have_get_coins = 0 # 这个变量以后可能会用上,先留着了 Have_coins = 0 -class mihoyobbs: +class Mihoyobbs: def __init__(self): self.headers = { "DS": tools.get_ds(web=False, web_old=False), @@ -37,17 +36,20 @@ class mihoyobbs: "bbs_Like_posts_num": 5, "bbs_Share": False } - self.Get_taskslist() + self.get_tasks_list() # 如果这三个任务都做了就没必要获取帖子了 if self.Task_do["bbs_Read_posts"] and self.Task_do["bbs_Like_posts"] and self.Task_do["bbs_Share"]: pass else: self.postsList = self.get_list() + def refresh_list(self) -> None: + self.postsList = self.get_list() + # 获取任务列表,用来判断做了哪些任务 - def Get_taskslist(self): - global Today_getcoins - global Today_have_getcoins + def get_tasks_list(self): + global today_get_coins + global today_have_get_coins global Have_coins log.info("正在获取任务列表") req = http.get(url=setting.bbs_Tasks_list, headers=self.headers) @@ -57,11 +59,11 @@ class mihoyobbs: config.clear_cookies() raise CookieError('Cookie expires') else: - Today_getcoins = data["data"]["can_get_points"] - Today_have_getcoins = data["data"]["already_received_points"] + today_get_coins = data["data"]["can_get_points"] + today_have_get_coins = data["data"]["already_received_points"] Have_coins = data["data"]["total_points"] # 如果当日可获取米游币数量为0直接判断全部任务都完成了 - if Today_getcoins == 0: + if today_get_coins == 0: self.Task_do["bbs_Sign"] = True self.Task_do["bbs_Read_posts"] = True self.Task_do["bbs_Like_posts"] = True @@ -69,10 +71,10 @@ class mihoyobbs: else: # 如果第0个大于或等于62则直接判定任务没做 if data["data"]["states"][0]["mission_id"] >= 62: - log.info(f"新的一天,今天可以获得{Today_getcoins}个米游币") + log.info(f"新的一天,今天可以获得{today_get_coins}个米游币") pass else: - log.info(f"似乎还有任务没完成,今天还能获得{Today_getcoins}") + log.info(f"似乎还有任务没完成,今天还能获得{today_get_coins}") for i in data["data"]["states"]: # 58是讨论区签到 if i["mission_id"] == 58: @@ -101,10 +103,16 @@ class mihoyobbs: def get_list(self) -> list: temp_list = [] log.info("正在获取帖子列表......") - req = http.get(url=setting.bbs_List_url.format(setting.mihoyobbs_List_Use[0]["forumId"]), headers=self.headers) - data = req.json() + req = http.get(url=setting.bbs_List_url.format(setting.mihoyobbs_List_Use[0]["forumId"]), + headers=self.headers) + data = req.json()["data"]["list"] for n in range(5): - temp_list.append([data["data"]["list"][n]["post"]["post_id"], data["data"]["list"][n]["post"]["subject"]]) + r_l = random.choice(data) + while r_l["post"]["subject"] in str(temp_list): + r_l = random.choice(data) + temp_list.append([r_l["post"]["post_id"], r_l["post"]["subject"]]) + # temp_list.append([data["data"]["list"][n]["post"]["post_id"], data["data"]["list"][n]["post"]["subject"]]) + log.info("已获取{}个帖子".format(len(temp_list))) return temp_list @@ -139,7 +147,7 @@ class mihoyobbs: time.sleep(random.randint(2, 8)) # 点赞 - def Likeposts(self): + def like_posts(self): if self.Task_do["bbs_Like_posts"]: log.info("点赞任务已经完成过了~") else: @@ -175,6 +183,6 @@ class mihoyobbs: log.info("分享任务执行成功......") break else: - log.debug(f"分享任务执行失败,正在执行第{i+2}次,共3次") + log.debug(f"分享任务执行失败,正在执行第{i + 2}次,共3次") time.sleep(random.randint(2, 8)) time.sleep(random.randint(2, 8)) From 8eccadae3ae128bfa01e36151b0a169494f460f9 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sat, 23 Apr 2022 10:40:07 +0800 Subject: [PATCH 08/45] =?UTF-8?q?=E5=90=8D=E7=A7=B0=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- push.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/push.py b/push.py index 6503a5f..3370764 100644 --- a/push.py +++ b/push.py @@ -57,7 +57,7 @@ def pushplus(status, push_message): # cq http协议的推送 -def cq_http(status, push_message): +def cqhttp(status, push_message): http.post( url=cfg.get('cqhttp', 'cqhttp_url'), json={ From 863dd718d0ba3f2851448d36fb9a814e73345be4 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:06:26 +0800 Subject: [PATCH 09/45] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 9 ++++----- docker.py | 1 + genshin.py | 3 ++- login.py | 11 ++++++----- main_multi.py | 5 +++-- request.py | 32 +++----------------------------- setting.py | 4 ++-- tools.py | 6 +++--- 8 files changed, 24 insertions(+), 47 deletions(-) diff --git a/config.py b/config.py index c9ab67d..2ca9f3a 100644 --- a/config.py +++ b/config.py @@ -72,8 +72,8 @@ def save_config(): data["mihoyobbs_Stoken"] = mihoyobbs_Stoken f.seek(0) f.truncate() - temp_Text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) - f.write(temp_Text) + temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) + f.write(temp_text) f.flush() f.close() log.info("Config保存完毕") @@ -89,9 +89,8 @@ def clear_cookies(): data["mihoyobbs_Cookies"] = "" f.seek(0) f.truncate() - temp_Text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) - f.write(temp_Text) + temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) + f.write(temp_text) f.flush() f.close() log.info("Cookie删除完毕") - diff --git a/docker.py b/docker.py index 940a531..30d4b4c 100644 --- a/docker.py +++ b/docker.py @@ -8,6 +8,7 @@ from crontab import CronTab time_format = "%Y-%m-%d %H:%M:%S" + def stop_me(_signo, _stack): log.info("Docker container has stoped....") exit(-1) diff --git a/genshin.py b/genshin.py index dedce53..2092f88 100644 --- a/genshin.py +++ b/genshin.py @@ -74,7 +74,8 @@ class Genshin: json={'act_id': setting.genshin_Act_id, 'region': i[2], 'uid': i[1]}) data = req.json() if data["retcode"] == 0: - log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[0 if sign_days == 0 else sign_days + 1])}") + log.info("旅行者{i[0]}签到成功~\r\n今天获得的奖励是" + f"{tools.get_item(self.sign_Give[0 if sign_days == 0 else sign_days + 1])}") sign_days += 1 elif data["retcode"] == -5003: log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}") diff --git a/login.py b/login.py index 57034d4..4172e5c 100644 --- a/login.py +++ b/login.py @@ -1,6 +1,6 @@ import config -import request import setting +from request import http from loghelper import log from error import CookieError @@ -12,16 +12,17 @@ def login(): raise CookieError('No cookie') # 判断Cookie里面是否有login_ticket 没有的话直接退了 if "login_ticket" in config.mihoyobbs_Cookies: - temp_Cookies = config.mihoyobbs_Cookies.split(";") - for i in temp_Cookies: + temp_cookies = config.mihoyobbs_Cookies.split(";") + for i in temp_cookies: if i.split("=")[0] == " login_ticket": config.mihoyobbs_Login_ticket = i.split("=")[1] break # 这里获取Stuid,但是实际是可以直接拿cookie里面的Uid - data = request.get(url=setting.bbs_Cookie_url.format(config.mihoyobbs_Login_ticket)) + data = http.get(url=setting.bbs_Cookie_url.format(config.mihoyobbs_Login_ticket)).json() if "成功" in data["data"]["msg"]: config.mihoyobbs_Stuid = str(data["data"]["cookie_info"]["account_id"]) - data = request.get(url=setting.bbs_Cookie_url2.format(config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid)) + data = http.get(url=setting.bbs_Cookie_url2.format( + config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid)).json() config.mihoyobbs_Stoken = data["data"]["list"][0]["token"] log.info("登录成功!") log.info("正在保存Config!") diff --git a/main_multi.py b/main_multi.py index 6cbde62..cad7378 100644 --- a/main_multi.py +++ b/main_multi.py @@ -32,7 +32,7 @@ def main_multi(autorun: bool): log.info(f"已搜索到{len(config_list)}个配置文件,请确认是否无多余文件!\r\n{config_list}") try: input("请输入回车继续,需要重新搜索配置文件请Ctrl+C退出脚本") - except: + except KeyboardInterrupt: exit(0) results = {"ok": [], "close": [], "error": []} for i in iter(config_list): @@ -51,7 +51,8 @@ def main_multi(autorun: bool): log.info(f"{i}执行完毕") time.sleep(random.randint(3, 10)) print("") - push_message = f'脚本执行完毕,共执行{len(config_list)}个配置文件,成功{len(results["ok"])}个,没执行{len(results["close"])}个,失败{len(results["error"])}个'\ + push_message = f'脚本执行完毕,共执行{len(config_list)}个配置文件,成功{len(results["ok"])}个,' \ + f'没执行{len(results["close"])}个,失败{len(results["error"])}个' \ f'\r\n没执行的配置文件: {results["close"]}\r\n执行失败的配置文件: {results["error"]}' log.info(push_message) push.push(0, push_message) diff --git a/request.py b/request.py index 8b090a1..c8fdd1d 100644 --- a/request.py +++ b/request.py @@ -5,39 +5,13 @@ try: http = httpx.Client(timeout=10, transport=httpx.HTTPTransport(retries=5)) # 当openssl版本小于1.0.2的时候直接进行一个空请求让httpx报错 import tools + if tools.get_openssl_version() <= 102: httpx.get() -except: +except (TypeError, ModuleNotFoundError): import requests from requests.adapters import HTTPAdapter + http = requests.Session() http.mount('http://', HTTPAdapter(max_retries=5)) http.mount('https://', HTTPAdapter(max_retries=5)) - - -# 这里实际上应该加个"-> dict"但是考虑到请求可能失败的关系,所以直接不声明返回变量 -def get(url: str, **headers: dict): - try: - req = http.get(url, headers=headers) - return req.json() - except: - print("请求失败,网络错误!") - return "" - - -def post(url: str, data: dict, **headers: dict): - try: - req = http.post(url, data=data, headers=headers) - return req.json() - except: - print("请求失败,网络错误!") - return "" - - -def post_json(url: str, json, **headers: dict): - try: - req = http.post(url, json=json, headers=headers) - return req.json() - except: - print("请求失败,网络错误!") - return "" diff --git a/setting.py b/setting.py index 0017246..e065b8d 100644 --- a/setting.py +++ b/setting.py @@ -73,13 +73,13 @@ honkai2_Sign_url = web_Api + "/event/luna/sign" # 崩坏3自动签到相关的设置 honkai3rd_Act_id = "ea20211026151532" -honkai3rd_Account_info_url = account_Info_url + "bh3_cn" # 废弃字段,之后可能会删除 +honkai3rd_Account_info_url = account_Info_url + "bh3_cn" # 废弃字段,之后可能会删除 honkai3rd_Is_signurl = web_Api + "/common/eutheniav2/index?act_id={}®ion={}&uid={}" honkai3rd_SignUrl = web_Api + "/common/eutheniav2/sign" # 原神自动签到相关的设置 genshin_Act_id = "e202009291139501" -genshin_Account_info_url = account_Info_url + "hk4e_cn" # 废弃字段,之后可能会删除 +genshin_Account_info_url = account_Info_url + "hk4e_cn" # 废弃字段,之后可能会删除 genshin_Signlisturl = web_Api + "/event/bbs_sign_reward/home?act_id={}" genshin_Is_signurl = web_Api + "/event/bbs_sign_reward/info?act_id={}®ion={}&uid={}" genshin_Signurl = web_Api + "/event/bbs_sign_reward/sign" diff --git a/tools.py b/tools.py index c8e5f03..5a42ca0 100644 --- a/tools.py +++ b/tools.py @@ -53,10 +53,10 @@ def get_item(raw_data: dict) -> str: # 获取明天早晨0点的时间戳 -def nextday() -> int: +def next_day() -> int: now_time = int(time.time()) - nextday_time = now_time - now_time % 86400 + time.timezone + 86400 - return nextday_time + next_day_time = now_time - now_time % 86400 + time.timezone + 86400 + return next_day_time # 获取Openssl版本 From 94f06127b4bc2aeb2b734e723ed9a9cc509f0241 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:08:08 +0800 Subject: [PATCH 10/45] =?UTF-8?q?readme=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bccaa64..e18b526 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ docker-compose logs -f 4. 提交方法选`本地上传文件夹`,并在下方的函数代码处上传整个项目文件夹。 -5. 执行方法填写 `index.main_handler`,多用户请填写`main_handler_mulit`. +5. 执行方法填写 `index.main_handler`,多用户请填写`index.main_handler_mulit`. 6. 展开高级配置,将执行超时时间修改为 `300 秒`,其他保持默认。 From b62a7b6b398e6e75589e949c11a10b17afb5da90 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:09:47 +0800 Subject: [PATCH 11/45] genshin.py --- genshin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genshin.py b/genshin.py index 2092f88..c106fac 100644 --- a/genshin.py +++ b/genshin.py @@ -74,7 +74,7 @@ class Genshin: json={'act_id': setting.genshin_Act_id, 'region': i[2], 'uid': i[1]}) data = req.json() if data["retcode"] == 0: - log.info("旅行者{i[0]}签到成功~\r\n今天获得的奖励是" + log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是" f"{tools.get_item(self.sign_Give[0 if sign_days == 0 else sign_days + 1])}") sign_days += 1 elif data["retcode"] == -5003: From 4c52b8c590b18e549a9842f552891e8aedd6257f Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:21:34 +0800 Subject: [PATCH 12/45] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=97=A7=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- push_main-pushplus.py | 40 ---------------------------------------- push_main-server.py | 38 -------------------------------------- 2 files changed, 78 deletions(-) delete mode 100644 push_main-pushplus.py delete mode 100644 push_main-server.py diff --git a/push_main-pushplus.py b/push_main-pushplus.py deleted file mode 100644 index 8e13297..0000000 --- a/push_main-pushplus.py +++ /dev/null @@ -1,40 +0,0 @@ -import sys -import time -import random -import subprocess -from request import http - -SendKey = "" -send_Url = "http://www.pushplus.plus/send" - -python_Path = sys.executable - -run_ShellCommand = python_Path + " main_multi.py autorun" - -for i in range(2): - opt_id, opt_info = subprocess.getstatusoutput(run_ShellCommand) - if opt_id == 0: - break - time.sleep(random.randint(30, 70)) - -if opt_id != 0: - print("Error!") - http.post( - url=send_Url, - data={ - "token": SendKey, - "title": "「米游社-签到」Error!", - "content": opt_info.split()[-1] + "\nHello!推送相关的设置已修改,请注意更新!\n这里是运行相关日志:\r\n" + opt_info, - } - ) -else: - print("OK!") - http.post( - url=send_Url, - data={ - "token": SendKey, - "title": "「米游社-签到」OK!", - "content": opt_info.split()[-1] + "\nHello!推送相关的设置已修改,请注意更新!\n这里是运行相关日志:\r\n" + opt_info, - } - ) -exit(0) diff --git a/push_main-server.py b/push_main-server.py deleted file mode 100644 index 9ad95a2..0000000 --- a/push_main-server.py +++ /dev/null @@ -1,38 +0,0 @@ -import sys -import time -import random -import subprocess -from request import http - -SendKey = "" -send_Url = f"https://sctapi.ftqq.com/{SendKey}.send" - -python_Path = sys.executable - -run_ShellCommand = python_Path + " main_multi.py autorun" - -for i in range(2): - opt_id, opt_info = subprocess.getstatusoutput(run_ShellCommand) - if opt_id == 0: - break - time.sleep(random.randint(30, 70)) - -if opt_id != 0: - print("Error!") - http.post( - url=send_Url, - data={ - "title": "米游社脚本执行出错!", - "desp": "\nHello!推送相关的设置已修改,请注意更新!\n这里是运行相关日志:\r\n" + opt_info - } - ) -else: - http.post( - url=send_Url, - data={ - "title": "米游社脚本执行成功", - "desp": "\nHello!推送相关的设置已修改,请注意更新!\n这里是运行相关日志:\r\n" + opt_info - } - ) - print("OK!") -exit(0) From 5ad6bc21c1a5f2245770e2b495e3a7d73e971936 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Mon, 25 Apr 2022 16:07:37 +0800 Subject: [PATCH 13/45] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 2 +- main.py | 2 ++ main_multi.py | 7 ++++++- push.py | 4 +++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config.py b/config.py index 2ca9f3a..cc3f2c4 100644 --- a/config.py +++ b/config.py @@ -86,7 +86,7 @@ def clear_cookies(): data["mihoyobbs_Login_ticket"] = "" data["mihoyobbs_Stuid"] = "" data["mihoyobbs_Stoken"] = "" - data["mihoyobbs_Cookies"] = "" + data["mihoyobbs_Cookies"] = "CookieError" f.seek(0) f.truncate() temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) diff --git a/main.py b/main.py index 0a4506e..885f5a0 100644 --- a/main.py +++ b/main.py @@ -81,6 +81,8 @@ def main(): else: log.info("崩坏3签到功能未启用!") return 0, return_data + elif config.mihoyobbs_Cookies == "CookieError": + raise CookieError('Cookie expires') else: log.warning("Config未启用!") return 1, "Config未启用!" diff --git a/main_multi.py b/main_multi.py index cad7378..3a74970 100644 --- a/main_multi.py +++ b/main_multi.py @@ -55,7 +55,12 @@ def main_multi(autorun: bool): f'没执行{len(results["close"])}个,失败{len(results["error"])}个' \ f'\r\n没执行的配置文件: {results["close"]}\r\n执行失败的配置文件: {results["error"]}' log.info(push_message) - push.push(0, push_message) + status = 0 + if len(results["error"]) == len(config_list): + status = 1 + elif len(results["error"]) < len(config_list): + status = 2 + push.push(status, push_message) if __name__ == "__main__": diff --git a/push.py b/push.py index 3370764..16135d6 100644 --- a/push.py +++ b/push.py @@ -18,8 +18,10 @@ def load_config(): def title(status): if status == 0: return "「米游社脚本」执行成功!" - else: + elif status == 1: return "「米游社脚本」执行失败!" + elif status == 2: + return "「米游社脚本」部分账号执行失败!" # telegram的推送 From aa6d63ea195ed393cb4456159f0a6d926d4e0a03 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Tue, 26 Apr 2022 06:54:34 +0800 Subject: [PATCH 14/45] fix multi --- main_multi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main_multi.py b/main_multi.py index 3a74970..5a09d0f 100644 --- a/main_multi.py +++ b/main_multi.py @@ -58,7 +58,7 @@ def main_multi(autorun: bool): status = 0 if len(results["error"]) == len(config_list): status = 1 - elif len(results["error"]) < len(config_list): + elif len(results["error"]) != 0: status = 2 push.push(status, push_message) From edb0f5463052808ffcec82648d7a58013aab0ff2 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Tue, 26 Apr 2022 15:49:55 +0800 Subject: [PATCH 15/45] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8D=E7=A7=B0&=E5=87=86=E5=A4=87=E5=BC=95=E5=85=A5v5?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 55 +++++++++++++++++++++++++++++----------------------- genshin.py | 2 +- honkai2.py | 2 +- honkai3rd.py | 2 +- login.py | 16 +++++++-------- main.py | 6 +++--- mihoyobbs.py | 2 +- tools.py | 2 +- 8 files changed, 47 insertions(+), 40 deletions(-) diff --git a/config.py b/config.py index cc3f2c4..bb69489 100644 --- a/config.py +++ b/config.py @@ -3,13 +3,13 @@ import json from loghelper import log # 是否启用config -enable_Config = True +enable = True # 这里的内容会自动获取 -mihoyobbs_Login_ticket = "" -mihoyobbs_Stuid = "" -mihoyobbs_Stoken = "" +login_ticket = "" +stuid = "" +stoken = "" # 这里是米游社的cookie -mihoyobbs_Cookies = "" +cookies = "" # 这个dist里面的内容和米游社有关 mihoyobbs = { # 全局开关,关闭之后下面的都不执行 @@ -41,25 +41,32 @@ path = os.path.dirname(os.path.realpath(__file__)) + "/config" config_Path = f"{path}/config.json" +def load_v4(data: dict): + global enable + global login_ticket + global stuid + global stoken + global cookies + global mihoyobbs + global genshin_Auto_sign + global honkai3rd_Auto_sign + enable = data["enable_Config"] + login_ticket = data["mihoyobbs_Login_ticket"] + stuid = data["mihoyobbs_Stuid"] + stoken = data["mihoyobbs_Stoken"] + cookies = data["mihoyobbs_Cookies"] + mihoyobbs = data["mihoyobbs"] + genshin_Auto_sign = data["genshin_Auto_sign"] + honkai3rd_Auto_sign = data["honkai3rd_Auto_sign"] + + def load_config(): with open(config_Path, "r") as f: data = json.load(f) - global enable_Config - global mihoyobbs_Login_ticket - global mihoyobbs_Stuid - global mihoyobbs_Stoken - global mihoyobbs_Cookies - global mihoyobbs - global genshin_Auto_sign - global honkai3rd_Auto_sign - enable_Config = data["enable_Config"] - mihoyobbs_Login_ticket = data["mihoyobbs_Login_ticket"] - mihoyobbs_Stuid = data["mihoyobbs_Stuid"] - mihoyobbs_Stoken = data["mihoyobbs_Stoken"] - mihoyobbs_Cookies = data["mihoyobbs_Cookies"] - mihoyobbs = data["mihoyobbs"] - genshin_Auto_sign = data["genshin_Auto_sign"] - honkai3rd_Auto_sign = data["honkai3rd_Auto_sign"] + if data.get('version') == 5: + pass + else: + load_v4(data) f.close() log.info("Config加载完毕") @@ -67,9 +74,9 @@ def load_config(): def save_config(): with open(config_Path, "r+") as f: data = json.load(f) - data["mihoyobbs_Login_ticket"] = mihoyobbs_Login_ticket - data["mihoyobbs_Stuid"] = mihoyobbs_Stuid - data["mihoyobbs_Stoken"] = mihoyobbs_Stoken + data["mihoyobbs_Login_ticket"] = login_ticket + data["mihoyobbs_Stuid"] = stuid + data["mihoyobbs_Stoken"] = stoken f.seek(0) f.truncate() temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) diff --git a/genshin.py b/genshin.py index c106fac..d6bc179 100644 --- a/genshin.py +++ b/genshin.py @@ -24,7 +24,7 @@ class Genshin: 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,en-US;q=0.8', 'X-Requested-With': 'com.mihoyo.hyperion', - "Cookie": config.mihoyobbs_Cookies, + "Cookie": config.cookies, 'x-rpc-device_id': tools.get_device_id() } self.acc_List = get_account_list("hk4e_cn", self.headers) diff --git a/honkai2.py b/honkai2.py index aefa515..00ffbcf 100644 --- a/honkai2.py +++ b/honkai2.py @@ -25,7 +25,7 @@ class Honkai2: 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,en-US;q=0.8', 'X-Requested-With': 'com.mihoyo.hyperion', - "Cookie": config.mihoyobbs_Cookies, + "Cookie": config.cookies, 'x-rpc-device_id': tools.get_device_id() } self.acc_List = get_account_list("bh2_cn", self.headers) diff --git a/honkai3rd.py b/honkai3rd.py index 09aba9a..f56ac1a 100644 --- a/honkai3rd.py +++ b/honkai3rd.py @@ -24,7 +24,7 @@ class Honkai3rd: 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,en-US;q=0.8', 'X-Requested-With': 'com.mihoyo.hyperion', - "Cookie": config.mihoyobbs_Cookies, + "Cookie": config.cookies, 'x-rpc-device_id': tools.get_device_id() } self.acc_List = get_account_list("bh3_cn", self.headers) diff --git a/login.py b/login.py index 4172e5c..5b5667e 100644 --- a/login.py +++ b/login.py @@ -6,24 +6,24 @@ from error import CookieError def login(): - if config.mihoyobbs_Cookies == '': + if config.cookies == '': log.error("请填入Cookies!") config.clear_cookies() raise CookieError('No cookie') # 判断Cookie里面是否有login_ticket 没有的话直接退了 - if "login_ticket" in config.mihoyobbs_Cookies: - temp_cookies = config.mihoyobbs_Cookies.split(";") + if "login_ticket" in config.cookies: + temp_cookies = config.cookies.split(";") for i in temp_cookies: if i.split("=")[0] == " login_ticket": - config.mihoyobbs_Login_ticket = i.split("=")[1] + config.login_ticket = i.split("=")[1] break # 这里获取Stuid,但是实际是可以直接拿cookie里面的Uid - data = http.get(url=setting.bbs_Cookie_url.format(config.mihoyobbs_Login_ticket)).json() + data = http.get(url=setting.bbs_Cookie_url.format(config.login_ticket)).json() if "成功" in data["data"]["msg"]: - config.mihoyobbs_Stuid = str(data["data"]["cookie_info"]["account_id"]) + config.stuid = str(data["data"]["cookie_info"]["account_id"]) data = http.get(url=setting.bbs_Cookie_url2.format( - config.mihoyobbs_Login_ticket, config.mihoyobbs_Stuid)).json() - config.mihoyobbs_Stoken = data["data"]["list"][0]["token"] + config.login_ticket, config.stuid)).json() + config.stoken = data["data"]["list"][0]["token"] log.info("登录成功!") log.info("正在保存Config!") config.save_config() diff --git a/main.py b/main.py index 885f5a0..c05bcc5 100644 --- a/main.py +++ b/main.py @@ -15,9 +15,9 @@ def main(): # 初始化,加载配置 return_data = "\n米游社: " config.load_config() - if config.enable_Config: + if config.enable: # 检测参数是否齐全,如果缺少就进行登入操作 - if config.mihoyobbs_Login_ticket == "" or config.mihoyobbs_Stuid == "" or config.mihoyobbs_Stoken == "": + if config.login_ticket == "" or config.stuid == "" or config.stoken == "": # 登入,如果没开启bbs全局没打开就无需进行登入操作 if config.mihoyobbs["bbs_Global"]: login.login() @@ -81,7 +81,7 @@ def main(): else: log.info("崩坏3签到功能未启用!") return 0, return_data - elif config.mihoyobbs_Cookies == "CookieError": + elif config.cookies == "CookieError": raise CookieError('Cookie expires') else: log.warning("Config未启用!") diff --git a/mihoyobbs.py b/mihoyobbs.py index 8e8d38b..a6571d8 100644 --- a/mihoyobbs.py +++ b/mihoyobbs.py @@ -16,7 +16,7 @@ class Mihoyobbs: def __init__(self): self.headers = { "DS": tools.get_ds(web=False, web_old=False), - "cookie": f"stuid={config.mihoyobbs_Stuid};stoken={config.mihoyobbs_Stoken}", + "cookie": f"stuid={config.stuid};stoken={config.stoken}", "x-rpc-client_type": setting.mihoyobbs_Client_type, "x-rpc-app_version": setting.mihoyobbs_Version, "x-rpc-sys_version": "6.0.1", diff --git a/tools.py b/tools.py index 5a42ca0..34f28c8 100644 --- a/tools.py +++ b/tools.py @@ -41,7 +41,7 @@ def get_ds(web: bool, web_old: bool) -> str: # 生成一个device id def get_device_id() -> str: - return str(uuid.uuid3(uuid.NAMESPACE_URL, config.mihoyobbs_Cookies)).replace( + return str(uuid.uuid3(uuid.NAMESPACE_URL, config.cookies)).replace( '-', '').upper() From 148e7e6025d4d193e12a6072f77e4e7e9542e37a Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Tue, 26 Apr 2022 15:59:28 +0800 Subject: [PATCH 16/45] =?UTF-8?q?=E4=BA=91=E5=87=BD=E6=95=B0=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 9 +++++++++ index.py | 3 +++ 2 files changed, 12 insertions(+) diff --git a/config.py b/config.py index bb69489..2eab14a 100644 --- a/config.py +++ b/config.py @@ -2,6 +2,9 @@ import os import json from loghelper import log +# 这个字段现在还没找好塞什么地方好,就先塞config这里了 +serverless = False + # 是否启用config enable = True # 这里的内容会自动获取 @@ -72,6 +75,9 @@ def load_config(): def save_config(): + if not serverless: + log.info("云函数执行,无法保存") + return None with open(config_Path, "r+") as f: data = json.load(f) data["mihoyobbs_Login_ticket"] = login_ticket @@ -87,6 +93,9 @@ def save_config(): def clear_cookies(): + if not serverless: + log.info("云函数执行,无法保存") + return None with open(config_Path, "r+") as f: data = json.load(f) data["enable_Config"] = False diff --git a/index.py b/index.py index 65c202b..d28e258 100644 --- a/index.py +++ b/index.py @@ -2,9 +2,11 @@ import main import push import main_multi from error import CookieError +from config import serverless def main_handler(event: dict, context: dict): + serverless = True try: status_code, push_message = main.main() except CookieError: @@ -15,6 +17,7 @@ def main_handler(event: dict, context: dict): def main_handler_mulit(event: dict, context: dict): + serverless = True # 多用户需要传递True表示自动执行,不需要手动进行确认 main_multi.main_multi(True) print("云函数多用户测试支持!") From e9749386f5d549353f486b265fd396bae426a6e6 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Tue, 26 Apr 2022 16:15:47 +0800 Subject: [PATCH 17/45] =?UTF-8?q?=E5=AF=B9=E5=8F=AA=E8=AF=BB=E6=83=85?= =?UTF-8?q?=E5=86=B5=E5=81=9A=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 33 +++++++++++++++++++++++---------- index.py | 6 +++--- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/config.py b/config.py index 2eab14a..6a8bc51 100644 --- a/config.py +++ b/config.py @@ -75,6 +75,7 @@ def load_config(): def save_config(): + global serverless if not serverless: log.info("云函数执行,无法保存") return None @@ -83,16 +84,23 @@ def save_config(): data["mihoyobbs_Login_ticket"] = login_ticket data["mihoyobbs_Stuid"] = stuid data["mihoyobbs_Stoken"] = stoken - f.seek(0) - f.truncate() temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) - f.write(temp_text) - f.flush() + try: + f.seek(0) + f.truncate() + f.write(temp_text) + f.flush() + except OSError: + serverless = True + log.info("Cookie保存失败") + exit(-1) + else: + log.info("Config保存完毕") f.close() - log.info("Config保存完毕") def clear_cookies(): + global serverless if not serverless: log.info("云函数执行,无法保存") return None @@ -103,10 +111,15 @@ def clear_cookies(): data["mihoyobbs_Stuid"] = "" data["mihoyobbs_Stoken"] = "" data["mihoyobbs_Cookies"] = "CookieError" - f.seek(0) - f.truncate() temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) - f.write(temp_text) - f.flush() + try: + f.seek(0) + f.truncate() + f.write(temp_text) + f.flush() + except OSError: + serverless = True + log.info("Cookie删除失败") + else: + log.info("Cookie删除完毕") f.close() - log.info("Cookie删除完毕") diff --git a/index.py b/index.py index d28e258..972af5c 100644 --- a/index.py +++ b/index.py @@ -1,12 +1,12 @@ import main import push +import config import main_multi from error import CookieError -from config import serverless def main_handler(event: dict, context: dict): - serverless = True + config.serverless = True try: status_code, push_message = main.main() except CookieError: @@ -17,7 +17,7 @@ def main_handler(event: dict, context: dict): def main_handler_mulit(event: dict, context: dict): - serverless = True + config.serverless = True # 多用户需要传递True表示自动执行,不需要手动进行确认 main_multi.main_multi(True) print("云函数多用户测试支持!") From f455a56ecd341201c0467fa09a4a10becf05e3a7 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Thu, 28 Apr 2022 13:50:25 +0800 Subject: [PATCH 18/45] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E4=BB=A5v5=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E8=BF=9B=E8=A1=8C=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD(=E6=9C=AA=E6=AD=A3=E5=BC=8F=E5=90=AF?= =?UTF-8?q?=E7=94=A8v5=E7=89=88=E6=9C=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account.py | 4 +-- config.py | 86 +++++++++++++++++++--------------------------------- genshin.py | 4 +-- honkai2.py | 2 +- honkai3rd.py | 2 +- login.py | 16 +++++----- main.py | 26 ++++++++-------- mihoyobbs.py | 4 +-- tools.py | 2 +- 9 files changed, 62 insertions(+), 84 deletions(-) diff --git a/account.py b/account.py index 7d6d031..078c663 100644 --- a/account.py +++ b/account.py @@ -18,12 +18,12 @@ def stop_module(game_id: str) -> None: # 崩坏2功能敬请期待 pass elif game_id == "bh3_cn": - config.honkai3rd_Auto_sign = False + config.config["games"]["cn"]["honkai3rd"] = False elif game_id == "nxx_cn": # 未定好像没米游社签到 pass elif game_id == "hk4e_cn": - config.genshin_Auto_sign = False + config.config["games"]["cn"]["genshin"] = False else: raise NameError config.save_config() diff --git a/config.py b/config.py index 6a8bc51..7048222 100644 --- a/config.py +++ b/config.py @@ -5,69 +5,47 @@ from loghelper import log # 这个字段现在还没找好塞什么地方好,就先塞config这里了 serverless = False -# 是否启用config -enable = True -# 这里的内容会自动获取 -login_ticket = "" -stuid = "" -stoken = "" -# 这里是米游社的cookie -cookies = "" -# 这个dist里面的内容和米游社有关 -mihoyobbs = { - # 全局开关,关闭之后下面的都不执行 - "bbs_Global": True, - # 讨论区签到 - "bbs_Signin": True, - # 多个讨论区签到 - "bbs_Signin_multi": True, - # 指定签到讨论区 - # 1是崩坏3 2是原神 3是崩坏2 4是未定事件簿 5是大别墅 - # 可以通过设置讨论区的id位置来设置主讨论区,[5,1]就是大别墅为主社区 - # 看帖子 点赞 分享帖子都是使用主社区获取到的列表 - "bbs_Signin_multi_list": [], - # 浏览3个帖子 - "bbs_Read_posts": True, - # 完成5次点赞 - "bbs_Like_posts": True, - # 完成后取消点赞 - "bbs_Unlike": True, - # 分享帖子 - "bbs_Share": True, -} -# 原神自动签到 -genshin_Auto_sign = True -# 崩坏3自动签到 -honkai3rd_Auto_sign = True +v5_config = '{"enable":false,"version":5,"account":{"cookie":"","login_ticket":"","stuid":"","stoken":""},"mihoyobbs":{' \ + '"enable":true,"checkin":true,"checkin_multi":true,"checkin_multi_list":[2,5],"read_posts":true,' \ + '"like_posts":true,"un_like":true,"share_post":true},"games":{"cn":{"enable":true,"hokai2":{' \ + '"auto_checkin":false,"black_list":[]},"honkai3rd":{"auto_checkin":false,"black_list":[]},' \ + '"tears_of_themis":{"auto_checkin":false,"black_list":[]},"genshin":{"auto_checkin":false,"black_list":[' \ + ']}},"os":{"enable":false,"cookie":"","genshin":{"auto_checkin":false,"black_list":[]}}}} ' +config = json.loads(v5_config) path = os.path.dirname(os.path.realpath(__file__)) + "/config" config_Path = f"{path}/config.json" def load_v4(data: dict): - global enable - global login_ticket - global stuid - global stoken - global cookies - global mihoyobbs - global genshin_Auto_sign - global honkai3rd_Auto_sign - enable = data["enable_Config"] - login_ticket = data["mihoyobbs_Login_ticket"] - stuid = data["mihoyobbs_Stuid"] - stoken = data["mihoyobbs_Stoken"] - cookies = data["mihoyobbs_Cookies"] - mihoyobbs = data["mihoyobbs"] - genshin_Auto_sign = data["genshin_Auto_sign"] - honkai3rd_Auto_sign = data["honkai3rd_Auto_sign"] + global config + # 配置开关 + config["enable"] = data["enable_Config"] + # 账号 cookie + config["account"]["login_ticket"] = data["mihoyobbs_Login_ticket"] + config["account"]["stuid"] = data["mihoyobbs_Stuid"] + config["account"]["stoken"] = data["mihoyobbs_Stoken"] + config["account"]["cookie"] = data["mihoyobbs_Cookies"] + # bbs 相关设置(自己之前造的孽) + config["mihoyobbs"]["enable"] = data["mihoyobbs"]["bbs_Global"] + config["mihoyobbs"]["checkin"] = data["mihoyobbs"]["bbs_Signin"] + config["mihoyobbs"]["checkin_multi"] = data["mihoyobbs"]["bbs_Signin_multi"] + config["mihoyobbs"]["checkin_multi_list"] = data["mihoyobbs"]["bbs_Signin_multi_list"] + config["mihoyobbs"]["read_post"] = data["mihoyobbs"]["bbs_Read_posts"] + config["mihoyobbs"]["like_post"] = data["mihoyobbs"]["bbs_Like_posts"] + config["mihoyobbs"]["un_like"] = data["mihoyobbs"]["bbs_Unlike"] + config["mihoyobbs"]["share_post"] = data["mihoyobbs"]["bbs_Share"] + # 游戏相关设置 v4只支持原神和崩坏3,所以其他选项默认关闭 + config["games"]["cn"]["genshin"] = data["genshin_Auto_sign"] + config["games"]["cn"]["honkai3rd"] = data["honkai3rd_Auto_sign"] def load_config(): + global config with open(config_Path, "r") as f: data = json.load(f) if data.get('version') == 5: - pass + config = data else: load_v4(data) f.close() @@ -81,9 +59,9 @@ def save_config(): return None with open(config_Path, "r+") as f: data = json.load(f) - data["mihoyobbs_Login_ticket"] = login_ticket - data["mihoyobbs_Stuid"] = stuid - data["mihoyobbs_Stoken"] = stoken + data["mihoyobbs_Login_ticket"] = config["account"]["login_ticket"] + data["mihoyobbs_Stuid"] = config["account"]["stuid"] + data["mihoyobbs_Stoken"] = config["account"]["stoken"] temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) try: f.seek(0) diff --git a/genshin.py b/genshin.py index d6bc179..697c284 100644 --- a/genshin.py +++ b/genshin.py @@ -24,7 +24,7 @@ class Genshin: 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,en-US;q=0.8', 'X-Requested-With': 'com.mihoyo.hyperion', - "Cookie": config.cookies, + "Cookie": config.config["account"]["cookie"], 'x-rpc-device_id': tools.get_device_id() } self.acc_List = get_account_list("hk4e_cn", self.headers) @@ -48,7 +48,7 @@ class Genshin: if data["retcode"] != 0: log.warning("获取账号签到信息失败!") print(req.text) - config.genshin_Auto_sign = False + config.config["games"]["cn"]["genshin"] = False config.save_config() raise CookieError("BBS Cookie Errror") return data["data"] diff --git a/honkai2.py b/honkai2.py index 00ffbcf..3cdc372 100644 --- a/honkai2.py +++ b/honkai2.py @@ -25,7 +25,7 @@ class Honkai2: 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,en-US;q=0.8', 'X-Requested-With': 'com.mihoyo.hyperion', - "Cookie": config.cookies, + "Cookie": config.config["account"]["cookie"], 'x-rpc-device_id': tools.get_device_id() } self.acc_List = get_account_list("bh2_cn", self.headers) diff --git a/honkai3rd.py b/honkai3rd.py index f56ac1a..a71cc24 100644 --- a/honkai3rd.py +++ b/honkai3rd.py @@ -24,7 +24,7 @@ class Honkai3rd: 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN,en-US;q=0.8', 'X-Requested-With': 'com.mihoyo.hyperion', - "Cookie": config.cookies, + "Cookie": config.config["account"]["cookie"], 'x-rpc-device_id': tools.get_device_id() } self.acc_List = get_account_list("bh3_cn", self.headers) diff --git a/login.py b/login.py index 5b5667e..fb1e2f5 100644 --- a/login.py +++ b/login.py @@ -6,24 +6,24 @@ from error import CookieError def login(): - if config.cookies == '': + if config.config["account"]["cookie"] == '': log.error("请填入Cookies!") config.clear_cookies() raise CookieError('No cookie') # 判断Cookie里面是否有login_ticket 没有的话直接退了 - if "login_ticket" in config.cookies: - temp_cookies = config.cookies.split(";") + if "login_ticket" in config.config["account"]["cookie"]: + temp_cookies = config.config["account"]["cookie"].split(";") for i in temp_cookies: if i.split("=")[0] == " login_ticket": - config.login_ticket = i.split("=")[1] + config.config["account"]["login_ticket"] = i.split("=")[1] break # 这里获取Stuid,但是实际是可以直接拿cookie里面的Uid - data = http.get(url=setting.bbs_Cookie_url.format(config.login_ticket)).json() + data = http.get(url=setting.bbs_Cookie_url.format(config.config["account"]["login_ticket"])).json() if "成功" in data["data"]["msg"]: - config.stuid = str(data["data"]["cookie_info"]["account_id"]) + config.config["account"]["stuid"] = str(data["data"]["cookie_info"]["account_id"]) data = http.get(url=setting.bbs_Cookie_url2.format( - config.login_ticket, config.stuid)).json() - config.stoken = data["data"]["list"][0]["token"] + config.config["account"]["login_ticket"], config.config["account"]["stuid"])).json() + config.config["account"]["stoken"] = data["data"]["list"][0]["token"] log.info("登录成功!") log.info("正在保存Config!") config.save_config() diff --git a/main.py b/main.py index c05bcc5..d616b67 100644 --- a/main.py +++ b/main.py @@ -15,17 +15,17 @@ def main(): # 初始化,加载配置 return_data = "\n米游社: " config.load_config() - if config.enable: + if config.config["enable"]: # 检测参数是否齐全,如果缺少就进行登入操作 - if config.login_ticket == "" or config.stuid == "" or config.stoken == "": + if config.config["account"]["login_ticket"] == "" or config.config["account"]["stuid"] == "" or config.config["account"]["stoken"] == "": # 登入,如果没开启bbs全局没打开就无需进行登入操作 - if config.mihoyobbs["bbs_Global"]: + if config.config["mihoyobbs"]["enable"] : login.login() time.sleep(random.randint(2, 8)) # 获取要使用的BBS列表,#判断是否开启bbs_Signin_multi - if config.mihoyobbs["bbs_Signin_multi"]: + if config.config["mihoyobbs"]["checkin_multi"] : # 用这里的方案可以实现当让id在第一个的时候为主社区 - for i in config.mihoyobbs["bbs_Signin_multi_list"]: + for i in config.config["mihoyobbs"]["checkin_multi_list"] : for i2 in setting.mihoyobbs_List: if i == int(i2["id"]): setting.mihoyobbs_List_Use.append(i2) @@ -35,7 +35,7 @@ def main(): if int(i["id"]) == 5: setting.mihoyobbs_List_Use.append(i) # 米游社签到 - if config.mihoyobbs["bbs_Global"]: + if config.config["mihoyobbs"]["enable"] : bbs = mihoyobbs.Mihoyobbs() if bbs.Task_do["bbs_Sign"] and bbs.Task_do["bbs_Read_posts"] and bbs.Task_do["bbs_Like_posts"] and \ bbs.Task_do["bbs_Share"]: @@ -47,13 +47,13 @@ def main(): while mihoyobbs.today_get_coins != 0 and i < 3: if i > 0: bbs.refresh_list() - if config.mihoyobbs["bbs_Signin"]: + if config.config["mihoyobbs"]["checkin"] : bbs.signing() - if config.mihoyobbs["bbs_Read_posts"]: + if config.config["mihoyobbs"]["read_post"] : bbs.read_posts() - if config.mihoyobbs["bbs_Like_posts"]: + if config.config["mihoyobbs"]["like_post"] : bbs.like_posts() - if config.mihoyobbs["bbs_Share"]: + if config.config["mihoyobbs"]["share_post"] : bbs.share_post() bbs.get_tasks_list() i += 1 @@ -66,7 +66,7 @@ def main(): return_data += "\n" + "米游社功能未启用!" log.info("米游社功能未启用!") # 原神签到 - if config.genshin_Auto_sign: + if config.config["games"]["cn"]["genshin"]: log.info("正在进行原神签到") genshin_help = genshin.Genshin() return_data += "\n\n" + genshin_help.sign_account() @@ -74,14 +74,14 @@ def main(): else: log.info("原神签到功能未启用!") # 崩坏3签到 - if config.honkai3rd_Auto_sign: + if config.config["games"]["cn"]["honkai3rd"]: log.info("正在进行崩坏3签到") honkai3rd_help = honkai3rd.Honkai3rd() return_data += "\n\n" + honkai3rd_help.sign_account() else: log.info("崩坏3签到功能未启用!") return 0, return_data - elif config.cookies == "CookieError": + elif config.config["account"]["cookie"] == "CookieError": raise CookieError('Cookie expires') else: log.warning("Config未启用!") diff --git a/mihoyobbs.py b/mihoyobbs.py index a6571d8..51b69ff 100644 --- a/mihoyobbs.py +++ b/mihoyobbs.py @@ -16,7 +16,7 @@ class Mihoyobbs: def __init__(self): self.headers = { "DS": tools.get_ds(web=False, web_old=False), - "cookie": f"stuid={config.stuid};stoken={config.stoken}", + "cookie": f'stuid={config.config["account"]["stuid"]};stoken={config.config["account"]["stoken"]}', "x-rpc-client_type": setting.mihoyobbs_Client_type, "x-rpc-app_version": setting.mihoyobbs_Version, "x-rpc-sys_version": "6.0.1", @@ -159,7 +159,7 @@ class Mihoyobbs: if data["message"] == "OK": log.debug("点赞:{} 成功".format(self.postsList[i][1])) # 判断取消点赞是否打开 - if config.mihoyobbs["bbs_Unlike"]: + if config.config["mihoyobbs"]["un_like"] : time.sleep(random.randint(2, 8)) req = http.post(url=setting.bbs_Like_url, headers=self.headers, json={"post_id": self.postsList[i][0], "is_cancel": True}) diff --git a/tools.py b/tools.py index 34f28c8..4709089 100644 --- a/tools.py +++ b/tools.py @@ -41,7 +41,7 @@ def get_ds(web: bool, web_old: bool) -> str: # 生成一个device id def get_device_id() -> str: - return str(uuid.uuid3(uuid.NAMESPACE_URL, config.cookies)).replace( + return str(uuid.uuid3(uuid.NAMESPACE_URL, config.config["account"]["cookie"])).replace( '-', '').upper() From 7b3e3ea045e861e6fbb0cc11a35c4b120013f548 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Thu, 28 Apr 2022 14:29:18 +0800 Subject: [PATCH 19/45] =?UTF-8?q?header=E5=A4=B4=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genshin.py | 22 ++++++---------------- honkai2.py | 24 +++++++----------------- honkai3rd.py | 24 +++++++----------------- setting.py | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 50 deletions(-) diff --git a/genshin.py b/genshin.py index 697c284..981b81a 100644 --- a/genshin.py +++ b/genshin.py @@ -11,22 +11,12 @@ from account import get_account_list class Genshin: def __init__(self) -> None: - self.headers = { - 'Accept': 'application/json, text/plain, */*', - 'DS': tools.get_ds(web=True, web_old=True), - 'Origin': 'https://webstatic.mihoyo.com', - 'x-rpc-app_version': setting.mihoyobbs_Version_old, - 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) ' - 'Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0', - 'x-rpc-client_type': setting.mihoyobbs_Client_type_web, - 'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true&act_id' - f'={setting.genshin_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon', - 'Accept-Encoding': 'gzip, deflate', - 'Accept-Language': 'zh-CN,en-US;q=0.8', - 'X-Requested-With': 'com.mihoyo.hyperion', - "Cookie": config.config["account"]["cookie"], - 'x-rpc-device_id': tools.get_device_id() - } + self.headers = setting.headers + self.headers['DS'] = tools.get_ds(web=True, web_old=True) + self.headers['Referer'] = 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true'\ + f'&act_id={setting.genshin_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon' + self.headers['Cookie'] = config.config["account"]["cookie"] + self.headers['x-rpc-device_id'] = tools.get_device_id() self.acc_List = get_account_list("hk4e_cn", self.headers) if len(self.acc_List) != 0: self.sign_Give = self.get_signgive() diff --git a/honkai2.py b/honkai2.py index 3cdc372..495ddad 100644 --- a/honkai2.py +++ b/honkai2.py @@ -11,22 +11,12 @@ from account import get_account_list class Honkai2: def __init__(self) -> None: - self.headers = { - 'Accept': 'application/json, text/plain, */*', - 'DS': tools.get_ds(web=True, web_old=True), - 'Origin': 'https://webstatic.mihoyo.com', - 'x-rpc-app_version': setting.mihoyobbs_Version_old, - 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) ' - 'Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0', - 'x-rpc-client_type': setting.mihoyobbs_Client_type_web, - 'Referer': 'https://webstatic.mihoyo.com/bbs/event/signin/bh2/index.html?bbs_auth_required=true&' - f'act_id={setting.honkai2_Act_id}&bbs_presentation_style=fullscreen&utm_source=bbs&' - 'utm_medium=mys&utm_campaign=icon', - 'Accept-Encoding': 'gzip, deflate', - 'Accept-Language': 'zh-CN,en-US;q=0.8', - 'X-Requested-With': 'com.mihoyo.hyperion', - "Cookie": config.config["account"]["cookie"], - 'x-rpc-device_id': tools.get_device_id() - } + self.headers = setting.headers + self.headers['DS'] = tools.get_ds(web=True, web_old=True) + self.headers['Referer'] = 'https://webstatic.mihoyo.com/bbs/event/signin/bh2/index.html?bbs_auth_required'\ + f'=true&act_id={setting.honkai2_Act_id}&bbs_presentation_style=fullscreen'\ + '&utm_source=bbs&utm_medium=mys&utm_campaign=icon' + self.headers['Cookie'] = config.config["account"]["cookie"] + self.headers['x-rpc-device_id'] = tools.get_device_id() self.acc_List = get_account_list("bh2_cn", self.headers) self.sign_day = 0 diff --git a/honkai3rd.py b/honkai3rd.py index a71cc24..5aa931b 100644 --- a/honkai3rd.py +++ b/honkai3rd.py @@ -10,23 +10,13 @@ from account import get_account_list class Honkai3rd: def __init__(self) -> None: - self.headers = { - 'Accept': 'application/json, text/plain, */*', - 'DS': tools.get_ds(web=True, web_old=True), - 'Origin': 'https://webstatic.mihoyo.com', - 'x-rpc-app_version': setting.mihoyobbs_Version_old, - 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) ' - 'Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0', - 'x-rpc-client_type': setting.mihoyobbs_Client_type_web, - 'Referer': f'https://webstatic.mihoyo.com/bh3/event/euthenia/index.html?bbs_presentation_style=fullscreen' - f'&bbs_game_role_required=bh3_cn&bbs_auth_required=t' - f'rue&act_id={setting.honkai3rd_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon', - 'Accept-Encoding': 'gzip, deflate', - 'Accept-Language': 'zh-CN,en-US;q=0.8', - 'X-Requested-With': 'com.mihoyo.hyperion', - "Cookie": config.config["account"]["cookie"], - 'x-rpc-device_id': tools.get_device_id() - } + self.headers = setting.headers + self.headers['DS'] = tools.get_ds(web=True, web_old=True) + self.headers['Referer'] = 'https://webstatic.mihoyo.com/bh3/event/euthenia/index.html?bbs_presentation_style' \ + '=fullscreen&bbs_game_role_required=bh3_cn&bbs_auth_required=true&act_id=' \ + f'{setting.honkai3rd_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon' + self.headers['Cookie'] = config.config["account"]["cookie"] + self.headers['x-rpc-device_id'] = tools.get_device_id() self.acc_List = get_account_list("bh3_cn", self.headers) self.sign_day = 0 diff --git a/setting.py b/setting.py index e065b8d..e12496f 100644 --- a/setting.py +++ b/setting.py @@ -50,6 +50,23 @@ game_id2name = { # Config Load之后run里面进行列表的选择 mihoyobbs_List_Use = [] +# 游戏签到的请求头 +headers = { + 'Accept': 'application/json, text/plain, */*', + 'DS': "", + 'Origin': 'https://webstatic.mihoyo.com', + 'x-rpc-app_version': mihoyobbs_Version_old, + 'User-Agent': 'Mozilla/5.0 (Linux; Android 9; Unspecified Device) AppleWebKit/537.36 (KHTML, like Gecko) ' + 'Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36 miHoYoBBS/2.3.0', + 'x-rpc-client_type': mihoyobbs_Client_type_web, + 'Referer': '', + 'Accept-Encoding': 'gzip, deflate', + 'Accept-Language': 'zh-CN,en-US;q=0.8', + 'X-Requested-With': 'com.mihoyo.hyperion', + "Cookie": "", + 'x-rpc-device_id': "" +} + # 通用设置 bbs_Api = "https://bbs-api.mihoyo.com" web_Api = "https://api-takumi.mihoyo.com" From 8f47a28b83eb9207be8662cd2994c0b90a55bd93 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Thu, 28 Apr 2022 14:42:20 +0800 Subject: [PATCH 20/45] =?UTF-8?q?=E9=99=88=E5=B9=B4=E8=80=81bug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=EF=BC=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genshin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/genshin.py b/genshin.py index 981b81a..e86aecd 100644 --- a/genshin.py +++ b/genshin.py @@ -58,6 +58,7 @@ class Genshin: ok = True if is_data["is_sign"]: log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}") + sign_days += 1 else: time.sleep(random.randint(2, 8)) req = http.post(url=setting.genshin_Signurl, headers=self.headers, @@ -66,7 +67,7 @@ class Genshin: if data["retcode"] == 0: log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是" f"{tools.get_item(self.sign_Give[0 if sign_days == 0 else sign_days + 1])}") - sign_days += 1 + sign_days += 2 elif data["retcode"] == -5003: log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}") else: @@ -74,7 +75,7 @@ class Genshin: print(req.text) ok = False if ok: - return_data += f"\n{i[0]}已连续签到{sign_days}天\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}" + return_data += f"\n{i[0]}已连续签到{sign_days}天\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days-1])}" else: return_data += f"\n{i[0]},本次签到失败" else: From 4843eb77e9aeda44a60765a8db60b352292fee36 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Thu, 28 Apr 2022 14:52:06 +0800 Subject: [PATCH 21/45] =?UTF-8?q?=E5=8E=9F=E7=A5=9E=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=B8=85=E7=90=86&=E5=B4=A9=E5=9D=8F3=E6=97=A5=E6=9C=9F?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D(=E5=8F=AF=E8=83=BD=E8=BF=98=E6=9C=89Bug)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genshin.py | 1 - honkai3rd.py | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/genshin.py b/genshin.py index e86aecd..fc4bb3c 100644 --- a/genshin.py +++ b/genshin.py @@ -72,7 +72,6 @@ class Genshin: log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}") else: log.warning("账号签到失败!") - print(req.text) ok = False if ok: return_data += f"\n{i[0]}已连续签到{sign_days}天\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days-1])}" diff --git a/honkai3rd.py b/honkai3rd.py index 5aa931b..7543c63 100644 --- a/honkai3rd.py +++ b/honkai3rd.py @@ -54,7 +54,7 @@ class Honkai3rd: today_item = self.get_today_item(data["data"]["sign"]["list"]) # 判断是否已经签到 if today_item["status"] == 0: - re_message = f"舰长 {i[0]} 今天已经签到过了~\t已连续签到{self.sign_day}天\t今天获得的奖励是{tools.get_item(today_item)}" + re_message = f"舰长 {i[0]} 今天已经签到过了~\t已连续签到{self.sign_day + 1}天\t今天获得的奖励是{tools.get_item(today_item)}" log.info(re_message) else: time.sleep(random.randint(2, 8)) @@ -63,14 +63,14 @@ class Honkai3rd: data = req.json() if data["retcode"] == 0: today_item = self.get_today_item(data["data"]["list"]) - re_message = f"舰长 {i[0]} 签到成功~\t已连续签到{self.sign_day}天\t今天获得的奖励是{tools.get_item(today_item)}" + re_message = f"舰长 {i[0]} 签到成功~\t已连续签到{self.sign_day + 2}天\t今天获得的奖励是{tools.get_item(today_item)}" log.info(re_message) elif data["retcode"] == -5003: - re_message = f"舰长 {i[0]} 今天已经签到过了~\t已连续签到{self.sign_day}天\t今天获得的奖励是{tools.get_item(today_item)}" + re_message = f"舰长 {i[0]} 今天已经签到过了~\t已连续签到{self.sign_day + 1}天\t今天获得的奖励是{tools.get_item(today_item)}" log.info(re_message) else: re_message = f"舰长 {i[0]} 本次签到失败!" log.warning(re_message) print(req.text) - return_data += re_message + return_data += "\r\n" + re_message return return_data From 62783135c55c525a23faaef94a9d2003cda1b5db Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Thu, 28 Apr 2022 15:08:27 +0800 Subject: [PATCH 22/45] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E9=BB=91=E5=90=8D=E5=8D=95(config=20v5=E5=8A=9F=E8=83=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account.py | 4 ++-- genshin.py | 4 +++- honkai3rd.py | 2 ++ main.py | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/account.py b/account.py index 078c663..8453ea1 100644 --- a/account.py +++ b/account.py @@ -18,12 +18,12 @@ def stop_module(game_id: str) -> None: # 崩坏2功能敬请期待 pass elif game_id == "bh3_cn": - config.config["games"]["cn"]["honkai3rd"] = False + config.config["games"]["cn"]["honkai3rd"]["auto_checkin"] = False elif game_id == "nxx_cn": # 未定好像没米游社签到 pass elif game_id == "hk4e_cn": - config.config["games"]["cn"]["genshin"] = False + config.config["games"]["cn"]["genshin"]["auto_checkin"] = False else: raise NameError config.save_config() diff --git a/genshin.py b/genshin.py index fc4bb3c..a3e974d 100644 --- a/genshin.py +++ b/genshin.py @@ -38,7 +38,7 @@ class Genshin: if data["retcode"] != 0: log.warning("获取账号签到信息失败!") print(req.text) - config.config["games"]["cn"]["genshin"] = False + config.config["games"]["cn"]["genshin"]["auto_checkin"] = False config.save_config() raise CookieError("BBS Cookie Errror") return data["data"] @@ -48,6 +48,8 @@ class Genshin: return_data = "原神: " if len(self.acc_List) != 0: for i in self.acc_List: + if i[1] in config.config["games"]["cn"]["genshin"]["black_list"]: + continue log.info(f"正在为旅行者{i[0]}进行签到...") time.sleep(random.randint(2, 8)) is_data = self.is_sign(region=i[2], uid=i[1]) diff --git a/honkai3rd.py b/honkai3rd.py index 7543c63..cecfb4f 100644 --- a/honkai3rd.py +++ b/honkai3rd.py @@ -41,6 +41,8 @@ class Honkai3rd: return_data += "\n并没有绑定任何崩坏3账号" else: for i in self.acc_List: + if i[1] in config.config["games"]["cn"]["honkai3rd"]["black_list"]: + continue log.info(f"正在为舰长 {i[0]} 进行签到...") req = http.get(setting.honkai3rd_Is_signurl.format(setting.honkai3rd_Act_id, i[2], i[1]), headers=self.headers) diff --git a/main.py b/main.py index d616b67..055c464 100644 --- a/main.py +++ b/main.py @@ -66,7 +66,7 @@ def main(): return_data += "\n" + "米游社功能未启用!" log.info("米游社功能未启用!") # 原神签到 - if config.config["games"]["cn"]["genshin"]: + if config.config["games"]["cn"]["genshin"]["auto_checkin"]: log.info("正在进行原神签到") genshin_help = genshin.Genshin() return_data += "\n\n" + genshin_help.sign_account() @@ -74,7 +74,7 @@ def main(): else: log.info("原神签到功能未启用!") # 崩坏3签到 - if config.config["games"]["cn"]["honkai3rd"]: + if config.config["games"]["cn"]["honkai3rd"]["auto_checkin"]: log.info("正在进行崩坏3签到") honkai3rd_help = honkai3rd.Honkai3rd() return_data += "\n\n" + honkai3rd_help.sign_account() From f0b2ebff170d6b7536a17c10cc870fc25350564a Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Thu, 28 Apr 2022 17:12:44 +0800 Subject: [PATCH 23/45] =?UTF-8?q?=E9=81=97=E6=BC=8F=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 7048222..6c7f9fc 100644 --- a/config.py +++ b/config.py @@ -36,8 +36,8 @@ def load_v4(data: dict): config["mihoyobbs"]["un_like"] = data["mihoyobbs"]["bbs_Unlike"] config["mihoyobbs"]["share_post"] = data["mihoyobbs"]["bbs_Share"] # 游戏相关设置 v4只支持原神和崩坏3,所以其他选项默认关闭 - config["games"]["cn"]["genshin"] = data["genshin_Auto_sign"] - config["games"]["cn"]["honkai3rd"] = data["honkai3rd_Auto_sign"] + config["games"]["cn"]["genshin"]["auto_checkin"] = data["genshin_Auto_sign"] + config["games"]["cn"]["honkai3rd"]["auto_checkin"] = data["honkai3rd_Auto_sign"] def load_config(): From 2388fba65d3aee6387a0ace478f6bfd9df0596e9 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Thu, 28 Apr 2022 22:28:16 +0800 Subject: [PATCH 24/45] bug fix --- config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 6c7f9fc..0dbb309 100644 --- a/config.py +++ b/config.py @@ -54,7 +54,7 @@ def load_config(): def save_config(): global serverless - if not serverless: + if serverless: log.info("云函数执行,无法保存") return None with open(config_Path, "r+") as f: @@ -79,7 +79,7 @@ def save_config(): def clear_cookies(): global serverless - if not serverless: + if serverless: log.info("云函数执行,无法保存") return None with open(config_Path, "r+") as f: From 884ddcd5f805a8775aa2c6ba37f39f6666d3f24f Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sat, 30 Apr 2022 09:00:07 +0800 Subject: [PATCH 25/45] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E4=BD=BF=E7=94=A8v5=20?= =?UTF-8?q?config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 23 +++++++------- config/config.json.example | 65 +++++++++++++++++++++++++++----------- genshin.py | 4 +-- honkai3rd.py | 2 +- 4 files changed, 61 insertions(+), 33 deletions(-) diff --git a/config.py b/config.py index 0dbb309..d1710ff 100644 --- a/config.py +++ b/config.py @@ -48,6 +48,9 @@ def load_config(): config = data else: load_v4(data) + log.info("升级v5 config") + # 直接升级到v5 config + save_config() f.close() log.info("Config加载完毕") @@ -58,11 +61,7 @@ def save_config(): log.info("云函数执行,无法保存") return None with open(config_Path, "r+") as f: - data = json.load(f) - data["mihoyobbs_Login_ticket"] = config["account"]["login_ticket"] - data["mihoyobbs_Stuid"] = config["account"]["stuid"] - data["mihoyobbs_Stoken"] = config["account"]["stoken"] - temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) + temp_text = json.dumps(config, sort_keys=False, indent=4, separators=(', ', ': ')) try: f.seek(0) f.truncate() @@ -78,18 +77,18 @@ def save_config(): def clear_cookies(): + global config global serverless if serverless: log.info("云函数执行,无法保存") return None with open(config_Path, "r+") as f: - data = json.load(f) - data["enable_Config"] = False - data["mihoyobbs_Login_ticket"] = "" - data["mihoyobbs_Stuid"] = "" - data["mihoyobbs_Stoken"] = "" - data["mihoyobbs_Cookies"] = "CookieError" - temp_text = json.dumps(data, sort_keys=False, indent=4, separators=(', ', ': ')) + config["enable"] = False + config["account"]["login_ticket"] = "" + config["account"]["stuid"] = "" + config["account"]["stoken"] = "" + config["account"]["cookie"] = "CookieError" + temp_text = json.dumps(config, sort_keys=False, indent=4, separators=(', ', ': ')) try: f.seek(0) f.truncate() diff --git a/config/config.json.example b/config/config.json.example index f847b83..a342553 100644 --- a/config/config.json.example +++ b/config/config.json.example @@ -1,20 +1,49 @@ { - "enable_Config": true, - "config_Version": 4, - "mihoyobbs_Login_ticket": "", - "mihoyobbs_Stuid": "", - "mihoyobbs_Stoken": "", - "mihoyobbs_Cookies": "", - "mihoyobbs": { - "bbs_Global": true, - "bbs_Signin": true, - "bbs_Signin_multi": true, - "bbs_Signin_multi_list": [2, 5], - "bbs_Read_posts": true, - "bbs_Like_posts": true, - "bbs_Unlike": true, - "bbs_Share": true - }, - "genshin_Auto_sign": true, - "honkai3rd_Auto_sign": false + "enable": false, + "version": 5, + "account": { + "cookie": "", + "login_ticket": "", + "stuid": "", + "stoken": "" + }, + "mihoyobbs": { + "enable": true, + "checkin": true, + "checkin_multi": true, + "checkin_multi_list": [2, 5], + "read_posts": true, + "like_posts": true, + "un_like": true, + "share_post": true + }, + "games": { + "cn": { + "enable": true, + "hokai2": { + "auto_checkin": false, + "black_list": [] + }, + "honkai3rd": { + "auto_checkin": false, + "black_list": [] + }, + "tears_of_themis": { + "auto_checkin": false, + "black_list": [] + }, + "genshin": { + "auto_checkin": false, + "black_list": [] + } + }, + "os": { + "enable": false, + "cookie": "", + "genshin": { + "auto_checkin": false, + "black_list": [] + } + } + } } \ No newline at end of file diff --git a/genshin.py b/genshin.py index a3e974d..401bbe3 100644 --- a/genshin.py +++ b/genshin.py @@ -32,7 +32,7 @@ class Genshin: return data["data"]["awards"] # 判断签到 - def is_sign(self, region: str, uid: str): + def is_sign(self, region: str, uid: str) -> dict: req = http.get(setting.genshin_Is_signurl.format(setting.genshin_Act_id, region, uid), headers=self.headers) data = req.json() if data["retcode"] != 0: @@ -44,7 +44,7 @@ class Genshin: return data["data"] # 签到 - def sign_account(self): + def sign_account(self) -> str: return_data = "原神: " if len(self.acc_List) != 0: for i in self.acc_List: diff --git a/honkai3rd.py b/honkai3rd.py index cecfb4f..ce41a09 100644 --- a/honkai3rd.py +++ b/honkai3rd.py @@ -34,7 +34,7 @@ class Honkai3rd: return raw_data[i] # 签到 - def sign_account(self): + def sign_account(self) -> str: return_data = "崩坏3: " if len(self.acc_List) == 0: log.warning("账号没有绑定任何崩坏3账号!") From cdc9172257c37338a42f7680dc185b00d4d80b53 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sat, 30 Apr 2022 12:38:52 +0800 Subject: [PATCH 26/45] fix bug --- config.py | 14 ++++++++++++-- main.py | 19 ++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/config.py b/config.py index d1710ff..6cc3924 100644 --- a/config.py +++ b/config.py @@ -31,8 +31,8 @@ def load_v4(data: dict): config["mihoyobbs"]["checkin"] = data["mihoyobbs"]["bbs_Signin"] config["mihoyobbs"]["checkin_multi"] = data["mihoyobbs"]["bbs_Signin_multi"] config["mihoyobbs"]["checkin_multi_list"] = data["mihoyobbs"]["bbs_Signin_multi_list"] - config["mihoyobbs"]["read_post"] = data["mihoyobbs"]["bbs_Read_posts"] - config["mihoyobbs"]["like_post"] = data["mihoyobbs"]["bbs_Like_posts"] + config["mihoyobbs"]["read_posts"] = data["mihoyobbs"]["bbs_Read_posts"] + config["mihoyobbs"]["like_posts"] = data["mihoyobbs"]["bbs_Like_posts"] config["mihoyobbs"]["un_like"] = data["mihoyobbs"]["bbs_Unlike"] config["mihoyobbs"]["share_post"] = data["mihoyobbs"]["bbs_Share"] # 游戏相关设置 v4只支持原神和崩坏3,所以其他选项默认关闭 @@ -46,6 +46,16 @@ def load_config(): data = json.load(f) if data.get('version') == 5: config = data + try: + config["mihoyobbs"]["like_post"] + except KeyError: + pass + else: + config["mihoyobbs"]["read_posts"] = config["mihoyobbs"]["read_post"] + config["mihoyobbs"]["like_posts"] = config["mihoyobbs"]["like_post"] + del config["mihoyobbs"]["like_post"] + del config["mihoyobbs"]["read_post"] + save_config() else: load_v4(data) log.info("升级v5 config") diff --git a/main.py b/main.py index 055c464..5dea979 100644 --- a/main.py +++ b/main.py @@ -17,15 +17,16 @@ def main(): config.load_config() if config.config["enable"]: # 检测参数是否齐全,如果缺少就进行登入操作 - if config.config["account"]["login_ticket"] == "" or config.config["account"]["stuid"] == "" or config.config["account"]["stoken"] == "": + if config.config["account"]["login_ticket"] == "" or config.config["account"]["stuid"] == "" or \ + config.config["account"]["stoken"] == "": # 登入,如果没开启bbs全局没打开就无需进行登入操作 - if config.config["mihoyobbs"]["enable"] : + if config.config["mihoyobbs"]["enable"]: login.login() time.sleep(random.randint(2, 8)) # 获取要使用的BBS列表,#判断是否开启bbs_Signin_multi - if config.config["mihoyobbs"]["checkin_multi"] : + if config.config["mihoyobbs"]["checkin_multi"]: # 用这里的方案可以实现当让id在第一个的时候为主社区 - for i in config.config["mihoyobbs"]["checkin_multi_list"] : + for i in config.config["mihoyobbs"]["checkin_multi_list"]: for i2 in setting.mihoyobbs_List: if i == int(i2["id"]): setting.mihoyobbs_List_Use.append(i2) @@ -35,7 +36,7 @@ def main(): if int(i["id"]) == 5: setting.mihoyobbs_List_Use.append(i) # 米游社签到 - if config.config["mihoyobbs"]["enable"] : + if config.config["mihoyobbs"]["enable"]: bbs = mihoyobbs.Mihoyobbs() if bbs.Task_do["bbs_Sign"] and bbs.Task_do["bbs_Read_posts"] and bbs.Task_do["bbs_Like_posts"] and \ bbs.Task_do["bbs_Share"]: @@ -47,13 +48,13 @@ def main(): while mihoyobbs.today_get_coins != 0 and i < 3: if i > 0: bbs.refresh_list() - if config.config["mihoyobbs"]["checkin"] : + if config.config["mihoyobbs"]["checkin"]: bbs.signing() - if config.config["mihoyobbs"]["read_post"] : + if config.config["mihoyobbs"]["read_posts"]: bbs.read_posts() - if config.config["mihoyobbs"]["like_post"] : + if config.config["mihoyobbs"]["like_posts"]: bbs.like_posts() - if config.config["mihoyobbs"]["share_post"] : + if config.config["mihoyobbs"]["share_post"]: bbs.share_post() bbs.get_tasks_list() i += 1 From b31fffb91c2b1992bf36173062eecebc13de5e29 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 1 May 2022 10:33:20 +0800 Subject: [PATCH 27/45] =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=90=8D=E4=BF=AE?= =?UTF-8?q?=E6=94=B9&Setting=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genshin.py | 22 +++++++++++----------- honkai3rd.py | 6 +++--- setting.py | 6 ++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/genshin.py b/genshin.py index 401bbe3..11c5c75 100644 --- a/genshin.py +++ b/genshin.py @@ -17,14 +17,14 @@ class Genshin: f'&act_id={setting.genshin_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon' self.headers['Cookie'] = config.config["account"]["cookie"] self.headers['x-rpc-device_id'] = tools.get_device_id() - self.acc_List = get_account_list("hk4e_cn", self.headers) - if len(self.acc_List) != 0: - self.sign_Give = self.get_signgive() + self.account_list = get_account_list("hk4e_cn", self.headers) + if len(self.account_list) != 0: + self.checkin_rewards = self.get_checkin_rewards() # 获取已经签到奖励列表 - def get_signgive(self) -> list: + def get_checkin_rewards(self) -> list: log.info("正在获取签到奖励列表...") - req = http.get(setting.genshin_Signlisturl.format(setting.genshin_Act_id), headers=self.headers) + req = http.get(setting.genshin_checkin_rewards, headers=self.headers) data = req.json() if data["retcode"] != 0: log.warning("获取签到奖励列表失败") @@ -46,8 +46,8 @@ class Genshin: # 签到 def sign_account(self) -> str: return_data = "原神: " - if len(self.acc_List) != 0: - for i in self.acc_List: + if len(self.account_list) != 0: + for i in self.account_list: if i[1] in config.config["games"]["cn"]["genshin"]["black_list"]: continue log.info(f"正在为旅行者{i[0]}进行签到...") @@ -59,7 +59,7 @@ class Genshin: sign_days = is_data["total_sign_day"] - 1 ok = True if is_data["is_sign"]: - log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}") + log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}") sign_days += 1 else: time.sleep(random.randint(2, 8)) @@ -68,15 +68,15 @@ class Genshin: data = req.json() if data["retcode"] == 0: log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是" - f"{tools.get_item(self.sign_Give[0 if sign_days == 0 else sign_days + 1])}") + f"{tools.get_item(self.checkin_rewards[0 if sign_days == 0 else sign_days + 1])}") sign_days += 2 elif data["retcode"] == -5003: - log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days])}") + log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}") else: log.warning("账号签到失败!") ok = False if ok: - return_data += f"\n{i[0]}已连续签到{sign_days}天\n今天获得的奖励是{tools.get_item(self.sign_Give[sign_days-1])}" + return_data += f"\n{i[0]}已连续签到{sign_days}天\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days - 1])}" else: return_data += f"\n{i[0]},本次签到失败" else: diff --git a/honkai3rd.py b/honkai3rd.py index ce41a09..c5407d3 100644 --- a/honkai3rd.py +++ b/honkai3rd.py @@ -17,7 +17,7 @@ class Honkai3rd: f'{setting.honkai3rd_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon' self.headers['Cookie'] = config.config["account"]["cookie"] self.headers['x-rpc-device_id'] = tools.get_device_id() - self.acc_List = get_account_list("bh3_cn", self.headers) + self.account_list = get_account_list("bh3_cn", self.headers) self.sign_day = 0 # 获取今天已经签到了的dict @@ -36,11 +36,11 @@ class Honkai3rd: # 签到 def sign_account(self) -> str: return_data = "崩坏3: " - if len(self.acc_List) == 0: + if len(self.account_list) == 0: log.warning("账号没有绑定任何崩坏3账号!") return_data += "\n并没有绑定任何崩坏3账号" else: - for i in self.acc_List: + for i in self.account_list: if i[1] in config.config["games"]["cn"]["honkai3rd"]["black_list"]: continue log.info(f"正在为舰长 {i[0]} 进行签到...") diff --git a/setting.py b/setting.py index e12496f..d9b6d90 100644 --- a/setting.py +++ b/setting.py @@ -84,19 +84,17 @@ bbs_Like_url = bbs_Api + "/apihub/sapi/upvotePost" # post json # 崩坏2自动签到相关的相关设置 honkai2_Act_id = "e202203291431091" -honkai2_Account_info_url = account_Info_url + "bh2_cn" # 废弃字段,之后可能会删除 +honkai2_checkin_rewards = f'{web_Api}/event/luna/home?lang=zh-cn&act_id={honkai2_Act_id}' honkai2_Is_signurl = web_Api + "/event/luna/info?lang=zh-cn&act_id={}®ion={}&uid={}" honkai2_Sign_url = web_Api + "/event/luna/sign" # 崩坏3自动签到相关的设置 honkai3rd_Act_id = "ea20211026151532" -honkai3rd_Account_info_url = account_Info_url + "bh3_cn" # 废弃字段,之后可能会删除 honkai3rd_Is_signurl = web_Api + "/common/eutheniav2/index?act_id={}®ion={}&uid={}" honkai3rd_SignUrl = web_Api + "/common/eutheniav2/sign" # 原神自动签到相关的设置 genshin_Act_id = "e202009291139501" -genshin_Account_info_url = account_Info_url + "hk4e_cn" # 废弃字段,之后可能会删除 -genshin_Signlisturl = web_Api + "/event/bbs_sign_reward/home?act_id={}" +genshin_checkin_rewards = f'{web_Api}/event/bbs_sign_reward/home?act_id={genshin_Act_id}' genshin_Is_signurl = web_Api + "/event/bbs_sign_reward/info?act_id={}®ion={}&uid={}" genshin_Signurl = web_Api + "/event/bbs_sign_reward/sign" From cdcd82dac1ec21a9f33baaff1d4f4d6d8403d2f2 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 1 May 2022 10:34:19 +0800 Subject: [PATCH 28/45] =?UTF-8?q?=E5=B4=A9=E5=9D=8F2=E7=AD=BE=E5=88=B0?= =?UTF-8?q?=E6=94=AF=E6=8C=81(copy=20genshin)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account.py | 4 +--- honkai2.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++--- main.py | 21 +++++++++------- 3 files changed, 80 insertions(+), 15 deletions(-) diff --git a/account.py b/account.py index 8453ea1..bd0fc57 100644 --- a/account.py +++ b/account.py @@ -14,9 +14,7 @@ def game_id2name(game_id: str) -> str: def stop_module(game_id: str) -> None: if game_id == "bh2_cn": - # config.honkai2rd_Auto_sign = False - # 崩坏2功能敬请期待 - pass + config.config["games"]["cn"]["hokai2"]["auto_checkin"] = False elif game_id == "bh3_cn": config.config["games"]["cn"]["honkai3rd"]["auto_checkin"] = False elif game_id == "nxx_cn": diff --git a/honkai2.py b/honkai2.py index 495ddad..ca2346a 100644 --- a/honkai2.py +++ b/honkai2.py @@ -13,10 +13,74 @@ class Honkai2: def __init__(self) -> None: self.headers = setting.headers self.headers['DS'] = tools.get_ds(web=True, web_old=True) - self.headers['Referer'] = 'https://webstatic.mihoyo.com/bbs/event/signin/bh2/index.html?bbs_auth_required'\ - f'=true&act_id={setting.honkai2_Act_id}&bbs_presentation_style=fullscreen'\ + self.headers['Referer'] = 'https://webstatic.mihoyo.com/bbs/event/signin/bh2/index.html?bbs_auth_required' \ + f'=true&act_id={setting.honkai2_Act_id}&bbs_presentation_style=fullscreen' \ '&utm_source=bbs&utm_medium=mys&utm_campaign=icon' self.headers['Cookie'] = config.config["account"]["cookie"] self.headers['x-rpc-device_id'] = tools.get_device_id() - self.acc_List = get_account_list("bh2_cn", self.headers) + self.account_list = get_account_list("bh2_cn", self.headers) self.sign_day = 0 + if len(self.account_list) != 0: + self.checkin_rewards = self.get_checkin_rewards() + + def get_checkin_rewards(self) -> list: + log.info("正在获取签到奖励列表...") + req = http.get(setting.honkai2_checkin_rewards, headers=self.headers) + data = req.json() + if data["retcode"] != 0: + log.warning("获取签到奖励列表失败") + print(req.text) + return data["data"]["awards"] + + # 判断签到 + def is_sign(self, region: str, uid: str) -> dict: + req = http.get(setting.honkai2_Is_signurl.format(setting.honkai2_Act_id, region, uid), headers=self.headers) + data = req.json() + if data["retcode"] != 0: + log.warning("获取账号签到信息失败!") + print(req.text) + config.config["games"]["cn"]["hokai2"]["auto_checkin"] = False + config.save_config() + raise CookieError("BBS Cookie Errror") + return data["data"] + + # 签到 + def sign_account(self) -> str: + return_data = "崩坏学园2: " + if len(self.account_list) != 0: + for i in self.account_list: + if i[1] in config.config["games"]["cn"]["hokai2"]["black_list"]: + continue + log.info(f"正在为崩坏2玩家: {i[0]}进行签到...") + time.sleep(random.randint(2, 8)) + is_data = self.is_sign(region=i[2], uid=i[1]) + if not is_data["is_sub"]: # 这个字段不知道干啥的,就先塞这里了 + log.warning(f"旅行者{i[0]}是第一次绑定米游社,请先手动签到一次") + else: + sign_days = is_data["total_sign_day"] - 1 + ok = True + if is_data["is_sign"]: + log.info(f"崩坏2玩家:{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}") + sign_days += 1 + else: + time.sleep(random.randint(2, 8)) + req = http.post(url=setting.honkai2_Sign_url, headers=self.headers, + json={'act_id': setting.honkai2_Act_id, 'region': i[2], 'uid': i[1]}) + data = req.json() + if data["retcode"] == 0: + log.info(f"崩坏2玩家:{i[0]}签到成功~\r\n今天获得的奖励是" + f"{tools.get_item(self.checkin_rewards[0 if sign_days == 0 else sign_days + 1])}") + sign_days += 2 + elif data["retcode"] == -5003: + log.info(f"崩坏2玩家:{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}") + else: + log.warning("账号签到失败!") + ok = False + if ok: + return_data += f"\n{i[0]}已连续签到{sign_days}天\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days - 1])}" + else: + return_data += f"\n{i[0]},本次签到失败" + else: + log.warning("账号没有绑定任何崩坏学园2账号!") + return_data += "\n并没有绑定任何崩坏学园2账号" + return return_data diff --git a/main.py b/main.py index 5dea979..1477be5 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ import push import login import config import random +import honkai2 import genshin import setting import mihoyobbs @@ -66,21 +67,23 @@ def main(): else: return_data += "\n" + "米游社功能未启用!" log.info("米游社功能未启用!") + # 崩坏2签到 config这里少了个n,下回config v6的时候再修复吧 + if config.config["games"]["cn"]["hokai2"]["auto_checkin"]: + log.info("正在进行崩坏2签到") + honkai2_help = honkai2.Honkai2() + return_data += "\n\n" + honkai2_help.sign_account() + time.sleep(random.randint(2, 8)) + # 崩坏3签到 + if config.config["games"]["cn"]["honkai3rd"]["auto_checkin"]: + log.info("正在进行崩坏3签到") + honkai3rd_help = honkai3rd.Honkai3rd() + return_data += "\n\n" + honkai3rd_help.sign_account() # 原神签到 if config.config["games"]["cn"]["genshin"]["auto_checkin"]: log.info("正在进行原神签到") genshin_help = genshin.Genshin() return_data += "\n\n" + genshin_help.sign_account() time.sleep(random.randint(2, 8)) - else: - log.info("原神签到功能未启用!") - # 崩坏3签到 - if config.config["games"]["cn"]["honkai3rd"]["auto_checkin"]: - log.info("正在进行崩坏3签到") - honkai3rd_help = honkai3rd.Honkai3rd() - return_data += "\n\n" + honkai3rd_help.sign_account() - else: - log.info("崩坏3签到功能未启用!") return 0, return_data elif config.config["account"]["cookie"] == "CookieError": raise CookieError('Cookie expires') From bae3920be792cdbe7ef6f2afb7442f25ecbabe3d Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 1 May 2022 13:55:00 +0800 Subject: [PATCH 29/45] =?UTF-8?q?readme=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e18b526..c4e5151 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ * 此项目的用途 - 这是一个米游社的辅助签到项目,包含了米游币和原神以及崩坏3 + 这是一个米游社的辅助签到项目,包含了米游币、崩坏2、崩坏3、原神,后续会支持未定事件簿 ## 如何使用程序 From ebb63a6393913610d9aa8b910a1ccf5061e67ae2 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 1 May 2022 22:33:01 +0800 Subject: [PATCH 30/45] =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=8A=9B=E5=BC=83is=5F?= =?UTF-8?q?sub=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- honkai2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/honkai2.py b/honkai2.py index ca2346a..74b0ff4 100644 --- a/honkai2.py +++ b/honkai2.py @@ -54,7 +54,8 @@ class Honkai2: log.info(f"正在为崩坏2玩家: {i[0]}进行签到...") time.sleep(random.randint(2, 8)) is_data = self.is_sign(region=i[2], uid=i[1]) - if not is_data["is_sub"]: # 这个字段不知道干啥的,就先塞这里了 + # if not is_data["is_sub"]: # 这个字段不知道干啥的,就先塞这里了 + if False: # 算了先改成false log.warning(f"旅行者{i[0]}是第一次绑定米游社,请先手动签到一次") else: sign_days = is_data["total_sign_day"] - 1 From 4ba03b79ded5e83128137a5d94368b47e5035eec Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Wed, 4 May 2022 12:43:47 +0800 Subject: [PATCH 31/45] update --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c4e5151..0d22518 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,12 @@ 7. **使用[获取Cookie](#获取米游社Cookie)里面的方法来获取米游社Cookie** - 8. 将复制的Cookie粘贴到`config.json`的`"mihoyobbs_Cookies":" "`中 + 8. 将复制的Cookie粘贴到`config.json`的`"cookie":" "`中(在`account`里面) 例子 > ```json - > "mihoyobbs_Cookies": "你复制的cookie" + > "cookie": "你复制的cookie" > ``` 9. 在命令提示符(cmd)/powershell,输入`python main.py`来进行执行 @@ -46,7 +46,7 @@ 3. 打开`http://bbs.mihoyo.com/ys/`并进行登入操作 -4. 在上一步登入完成后新建标签页,打开`http://user.mihoyo.com/`并进行登入操作 (如果你不需要自动获取米游币可以忽略这个步骤,并把`bbs_Global`改为`false`即可) +4. 在上一步登入完成后新建标签页,打开`http://user.mihoyo.com/`并进行登入操作 (如果你不需要自动获取米游币可以忽略这个步骤,并把`mihoyobbs`的`enable`改为`false`即可) 5. 按下键盘上的`F12`或右键检查,打开开发者工具,点击Console From 770d13f61cbe5b22ec5c86ab910cab8e38cabe3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=AD=E7=BE=B2?= Date: Sat, 7 May 2022 15:19:18 +0800 Subject: [PATCH 32/45] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=92=89=E9=92=89?= =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 庭羲 --- config.py | 34 +++++++++++++++++++++++++++------- config/README.md | 36 ++++++++++++++++++------------------ config/push.ini.example | 9 ++++++--- push.py | 20 +++++++++++++++++++- 4 files changed, 70 insertions(+), 29 deletions(-) diff --git a/config.py b/config.py index 6cc3924..de27cc2 100644 --- a/config.py +++ b/config.py @@ -5,13 +5,33 @@ from loghelper import log # 这个字段现在还没找好塞什么地方好,就先塞config这里了 serverless = False -v5_config = '{"enable":false,"version":5,"account":{"cookie":"","login_ticket":"","stuid":"","stoken":""},"mihoyobbs":{' \ - '"enable":true,"checkin":true,"checkin_multi":true,"checkin_multi_list":[2,5],"read_posts":true,' \ - '"like_posts":true,"un_like":true,"share_post":true},"games":{"cn":{"enable":true,"hokai2":{' \ - '"auto_checkin":false,"black_list":[]},"honkai3rd":{"auto_checkin":false,"black_list":[]},' \ - '"tears_of_themis":{"auto_checkin":false,"black_list":[]},"genshin":{"auto_checkin":false,"black_list":[' \ - ']}},"os":{"enable":false,"cookie":"","genshin":{"auto_checkin":false,"black_list":[]}}}} ' -config = json.loads(v5_config) +config = { + 'enable': True, 'version': 5, + 'account': { + 'cookie': '', + 'login_ticket': '', + 'stuid': '', + 'stoken': '' + }, + 'mihoyobbs': { + 'enable': True, 'checkin': True, 'checkin_multi': True, 'checkin_multi_list': [2, 5], + 'read_posts': True, 'like_posts': True, 'un_like': True, 'share_post': True + }, + 'games': { + 'cn': { + 'enable': True, + 'genshin': {'auto_checkin': True, 'black_list': []}, + 'hokai2': {'auto_checkin': False, 'black_list': []}, + 'honkai3rd': {'auto_checkin': False, 'black_list': []}, + 'tears_of_themis': {'auto_checkin': False, 'black_list': []}, + }, + 'os': { + 'enable': False, 'cookie': '', + 'genshin': {'auto_checkin': False, 'black_list': []} + } + } +} + path = os.path.dirname(os.path.realpath(__file__)) + "/config" config_Path = f"{path}/config.json" diff --git a/config/README.md b/config/README.md index 9143b1c..7afe76b 100644 --- a/config/README.md +++ b/config/README.md @@ -13,10 +13,10 @@ >此字段的作用是是否启用这个配置文件,`bool`类型,可设置`true`(默认)和`false` ```json -"config_Version": 3, +"config_Version": 5, ``` ->此字段的作用是表明配置文件版本(不过脚本里面暂时没有用到),`int`类型 +>此字段的作用是表明配置文件版本(4会被转成5),`int`类型 ```json "mihoyobbs_Login_ticket": "", @@ -44,34 +44,34 @@ ```json "mihoyobbs": { - "bbs_Global": true, - "bbs_Signin": true, - "bbs_Signin_multi": true, - "bbs_Signin_multi_list": [2, 5], - "bbs_Read_posts": true, - "bbs_Like_posts": true, - "bbs_Unlike": true, - "bbs_Share": true + "enable": true, + "checkin": true, + "checkin_multi": true, + "checkin_multi_list": [2, 5], + "read_posts": true, + "like_posts": true, + "un_like": true, + "share_post": true }, ``` 此字段的作用是米游币获取相关的设置,`object`类型(**python**里面是`dict`) ->`bbs_Global`的作用是是否启用米游币获取,`bool`类型,可设置`true`(默认)和`false` +>`enable`的作用是是否启用米游币获取,`bool`类型,可设置`true`(默认)和`false` > ->`bbs_Signin`的作用是是否启用讨论区自动签到,`bool`类型,可设置`true`(默认)和`false` +>`checkin`的作用是是否启用讨论区自动签到,`bool`类型,可设置`true`(默认)和`false` > ->`bbs_Signin_multi`的作用是是否启用多个讨论区签到(关闭的话只签到大别墅),`bool`类型,可设置`true`(默认)和`false` +>`checkin_multi`的作用是是否启用多个讨论区签到(关闭的话只签到大别墅),`bool`类型,可设置`true`(默认)和`false` > ->`bbs_Signin_multi_list`的作用设置要签到的讨论区,`array`类型(**python**里面是`list`),可设置内容可以设置`[1,2,3,4,5]`签到全部讨论区,默认是`[2,5]`,可以通过调整id的位置来进行设置阅读/点赞/分享指定讨论区的帖子`[2,1,5]`(签到原神,崩坏3和大别墅)[讨论区的id对应关系](## 讨论区的id对应关系) +>`checkin_multi_list`的作用设置要签到的讨论区,`array`类型(**python**里面是`list`),可设置内容可以设置`[1,2,3,4,5]`签到全部讨论区,默认是`[2,5]`,可以通过调整id的位置来进行设置阅读/点赞/分享指定讨论区的帖子`[2,1,5]`(签到原神,崩坏3和大别墅)[讨论区的id对应关系](## 讨论区的id对应关系) > ->`bbs_Read_posts`的作用是是否启用自动阅读帖子,`bool`类型,可设置`true`(默认)和`false` +>`read_posts`的作用是是否启用自动阅读帖子,`bool`类型,可设置`true`(默认)和`false` > ->`bbs_Like_posts`的作用是是否启用自动点赞帖子,`bool`类型,可设置`true`(默认)和`false` +>`like_posts`的作用是是否启用自动点赞帖子,`bool`类型,可设置`true`(默认)和`false` > ->`bbs_Unlike`的作用是是否启用自动取消帖子点赞(当`bbs_Like_posts`为`false`时本设置无效),`bool`类型,可设置`true`(默认)和`false` +>`un_like`的作用是是否启用自动取消帖子点赞(当`like_posts`为`false`时本设置无效),`bool`类型,可设置`true`(默认)和`false` > ->`bbs_Share`的作用是是否启用自动分享帖子,`bool`类型,可设置`true`(默认)和`false` +>`share_post`的作用是是否启用自动分享帖子,`bool`类型,可设置`true`(默认)和`false` ```json "genshin_Auto_sign": true, diff --git a/config/push.ini.example b/config/push.ini.example index fc306dd..7872516 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -1,8 +1,8 @@ [setting] enable=false -#共有 cqhttp ftqq(sever酱) pushplus telegram +#共有 cqhttp ftqq(sever酱) pushplus telegram dingrobot push_server=cqhttp -#server酱和pushplus的推送token +#server酱 pushplus dingrobot 的推送token push_token=123456 [cqhttp] @@ -24,4 +24,7 @@ wechat_id= [pushdeer] api_url=https://api2.pushdeer.com -token= \ No newline at end of file +token= + +[dingrobot] +api_url=https://oapi.dingtalk.com/robot/send \ No newline at end of file diff --git a/push.py b/push.py index 16135d6..ec06088 100644 --- a/push.py +++ b/push.py @@ -99,6 +99,20 @@ def pushdeer(status, push_message): ) +# dingding robot +def dingrobot(status, push_message): + # print('dingrobot', title(status) + "\r\n" + push_message) + access_token=cfg.get('setting', 'push_token') + # print(f"https://oapi.dingtalk.com/robot/send?access_token={access_token}") + rep = http.post( + url=f"https://oapi.dingtalk.com/robot/send?access_token={access_token}", + headers={"Content-Type": "application/json; charset=utf-8"}, + json={ + "msgtype": "text", "text": { "content": title(status) + "\r\n" + push_message } + } + ).json() + print(rep) + def push(status, push_message): if not load_config(): return 0 @@ -107,9 +121,13 @@ def push(status, push_message): log.info("正在执行推送......") try: log.debug(f"推送所用的服务为:{push_server}") - eval(push_server[:10].lower() + "(status, push_message)") + eval(push_server[:10] + "(status, push_message)") except NameError: log.warning("推送服务名称错误") else: log.info("推送完毕......") return 0 + +if __name__ == "__main__": + push(0, '推送正文') + From 4321899e1a1ac08bef59cd3f6197e07427d1f58d Mon Sep 17 00:00:00 2001 From: Seele <48525679+Seele0oO@users.noreply.github.com> Date: Sun, 8 May 2022 14:18:06 +0800 Subject: [PATCH 33/45] add Aliyun --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d22518..cfb6fec 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,9 @@ docker-compose logs -f ## 使用云函数运行 ->以腾讯云为例 +**腾讯云函数服务免费额度近期有变化,为了避免产生费用,建议切换到阿里云 函数计算 FC** + +>腾讯云 1. 在本地完整运行一次。 @@ -104,6 +106,24 @@ docker-compose logs -f 8. 完成,enjoy it! +>阿里云 + + 1. 在本地完整运行一次。 + 2. 打开并登录[函数计算 FC](https://fcnext.console.aliyun.com/cn-hangzhou/services)。注意左上方显示的地区,可点击切换其他地区。 + 3. 创建服务 (日志功能可能产生费用,建议关闭) + 1. - 创建函数 + 2. 从零开始创建 + 1. `请求处理程序类型:处理事件请求` + 2. `请求处理程序:index.main_handler`,多用户请填写`index.main_handler_mulit` + 3. 配置触发器:触发器类型 定时触发器 异步调用。建议触发方式设为`指定时间` + 4. 点击创建 + 3. 进入函数详情 + 1. 打开函数配置 + 2. 修改 `环境信息` - `执行超时时间` 为300秒。 + 4. 测试运行 + 1. 打开 `函数详情` + 2. 点击`测试函数` + 5. 完成 ## 使用的第三方库 requests: [github](https://github.com/psf/requests) [pypi](https://pypi.org/project/requests/) From 020f403b28504fba890149914fae2ee840df1109 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 8 May 2022 20:38:28 +0800 Subject: [PATCH 34/45] readme --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cfb6fec..78c7b7f 100644 --- a/README.md +++ b/README.md @@ -111,19 +111,20 @@ docker-compose logs -f 1. 在本地完整运行一次。 2. 打开并登录[函数计算 FC](https://fcnext.console.aliyun.com/cn-hangzhou/services)。注意左上方显示的地区,可点击切换其他地区。 3. 创建服务 (日志功能可能产生费用,建议关闭) - 1. - 创建函数 + 1. 创建函数 2. 从零开始创建 - 1. `请求处理程序类型:处理事件请求` - 2. `请求处理程序:index.main_handler`,多用户请填写`index.main_handler_mulit` + 1. `请求处理程序类型:处理事件请求` + 2. `请求处理程序:index.main_handler`,多用户请填写`index.main_handler_mulit` 3. 配置触发器:触发器类型 定时触发器 异步调用。建议触发方式设为`指定时间` 4. 点击创建 3. 进入函数详情 1. 打开函数配置 2. 修改 `环境信息` - `执行超时时间` 为300秒。 4. 测试运行 - 1. 打开 `函数详情` + 1. 打开 `函数详情` 2. 点击`测试函数` 5. 完成 + ## 使用的第三方库 requests: [github](https://github.com/psf/requests) [pypi](https://pypi.org/project/requests/) From dc27a615c9a39831e61762faf41e9829fe108447 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 8 May 2022 20:39:25 +0800 Subject: [PATCH 35/45] =?UTF-8?q?config=E6=A8=A1=E6=9D=BF=E7=9A=84enable?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E9=BB=98=E8=AE=A4true?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.json.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.json.example b/config/config.json.example index a342553..aec32bc 100644 --- a/config/config.json.example +++ b/config/config.json.example @@ -1,5 +1,5 @@ { - "enable": false, + "enable": true, "version": 5, "account": { "cookie": "", From 734ac90426108c62a88f556a712f005e651015ec Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 8 May 2022 20:44:11 +0800 Subject: [PATCH 36/45] =?UTF-8?q?=E7=BB=9D=E5=8C=BA=E9=9B=B6=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setting.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setting.py b/setting.py index d9b6d90..7497d00 100644 --- a/setting.py +++ b/setting.py @@ -39,6 +39,11 @@ mihoyobbs_List = [{ "forumId": "52", "name": "崩坏:星穹铁道", "url": "https://bbs.mihoyo.com/sr/" +}, { + "id": "8", + "forumId": "57", + "name": "绝区零", + "url": "https://bbs.mihoyo.com/zzz/" }] game_id2name = { From b481d5a713a852b1dc7c30f61fd6cdcb34111c5b Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sun, 8 May 2022 21:21:39 +0800 Subject: [PATCH 37/45] =?UTF-8?q?readme=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 78c7b7f..0129868 100644 --- a/README.md +++ b/README.md @@ -86,9 +86,9 @@ docker-compose logs -f ## 使用云函数运行 -**腾讯云函数服务免费额度近期有变化,为了避免产生费用,建议切换到阿里云 函数计算 FC** +腾讯云函数服务免费额度近期有变化,为了**避免产生费用**,建议切换到阿里云 函数计算 FC ->腾讯云 +* 腾讯云 1. 在本地完整运行一次。 @@ -106,7 +106,7 @@ docker-compose logs -f 8. 完成,enjoy it! ->阿里云 +* 阿里云 1. 在本地完整运行一次。 2. 打开并登录[函数计算 FC](https://fcnext.console.aliyun.com/cn-hangzhou/services)。注意左上方显示的地区,可点击切换其他地区。 @@ -139,6 +139,10 @@ httpx: [github](https://github.com/encode/httpx) [pypi](https://pypi.org/project 推荐使用 阿里云/腾讯云 的云函数来进行每日自动执行脚本。 +## Stargazers over time + +![Stargazers over time](https://starchart.cc/Womsxd/AutoMihoyoBBS.svg) + ## License [MIT License](https://github.com/Womsxd/AutoMihoyoBBS/blob/master/LICENSE) From 9235b1714816ec3d095e8f2ce67c875c41043f5b Mon Sep 17 00:00:00 2001 From: TingHsi Date: Sun, 8 May 2022 23:50:04 +0800 Subject: [PATCH 38/45] =?UTF-8?q?=E9=92=89=E9=92=89=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE=E5=8A=A0=E7=AD=BE?= =?UTF-8?q?=E5=AF=86=E9=92=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: TingHsi --- config/README.md | 26 +++++++++++++++++++++ config/push.ini.example | 2 +- push.py | 52 +++++++++++++++++++++++++++++------------ 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/config/README.md b/config/README.md index 7afe76b..70c1e14 100644 --- a/config/README.md +++ b/config/README.md @@ -98,3 +98,29 @@ `5`对应大别墅 `6`对应崩坏:星穹铁道 + + +# push.ini配置教程 + +* push_server 可选范围 cqhttp ftqq(sever酱) pushplus telegram dingrobot + + +## dingrobot +钉钉群机器人 + +[dingrobot]中的api_url填写**Webhook**地址 + +[setting]中的**push_token**用于填写**安全设置**中**加签**的密钥,此选项为可选项 + +填写示例 + +```ini +[setting] +enable=true +push_server=dingrobot +push_token= + +[dingrobot] +api_url=https://oapi.dingtalk.com/robot/send?access_token=XXX +``` + diff --git a/config/push.ini.example b/config/push.ini.example index 7872516..4d99f60 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -27,4 +27,4 @@ api_url=https://api2.pushdeer.com token= [dingrobot] -api_url=https://oapi.dingtalk.com/robot/send \ No newline at end of file +api_url=https://oapi.dingtalk.com/robot/send?access_token=XXX \ No newline at end of file diff --git a/push.py b/push.py index ec06088..9b14b48 100644 --- a/push.py +++ b/push.py @@ -1,4 +1,9 @@ import os +import time +import base64 +import hashlib +import urllib +import hmac from request import http from loghelper import log from configparser import ConfigParser @@ -98,36 +103,53 @@ def pushdeer(status, push_message): } ) - -# dingding robot +# 钉钉群机器人 def dingrobot(status, push_message): - # print('dingrobot', title(status) + "\r\n" + push_message) - access_token=cfg.get('setting', 'push_token') - # print(f"https://oapi.dingtalk.com/robot/send?access_token={access_token}") + api_url = cfg.get('dingrobot', 'api_url') # https://oapi.dingtalk.com/robot/send?access_token=XXX + secret = cfg.get('setting', 'push_token') # 安全设置 -> 加签 -> 密钥 + + if secret: + timestamp = str(round(time.time() * 1000)) + sign_string = f"{timestamp}\n{secret}" + hmac_code = hmac.new( + key=secret.encode("utf-8"), + msg=sign_string.encode("utf-8"), + digestmod=hashlib.sha256 + ).digest() + sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) + api_url = f"{api_url}×tamp={timestamp}&sign={sign}" + rep = http.post( - url=f"https://oapi.dingtalk.com/robot/send?access_token={access_token}", + url=api_url, headers={"Content-Type": "application/json; charset=utf-8"}, json={ "msgtype": "text", "text": { "content": title(status) + "\r\n" + push_message } } ).json() - print(rep) + log.info(f"推送结果:{rep.get('errmsg')}") def push(status, push_message): if not load_config(): return 0 if cfg.getboolean('setting', 'enable'): - push_server = cfg.get('setting', 'push_server').lower() log.info("正在执行推送......") + func_name = cfg.get('setting', 'push_server').lower() + func = globals().get(func_name) + # print(func) + if not func: + log.warning("推送服务名称错误:请检查config/push.ini -> [setting] -> push_server") + return 0 + log.debug(f"推送所用的服务为:{func_name}") try: - log.debug(f"推送所用的服务为:{push_server}") - eval(push_server[:10] + "(status, push_message)") - except NameError: - log.warning("推送服务名称错误") + # eval(push_server[:10] + "(status, push_message)") + # 与面代码等效 20220508 + func(status, push_message) + except: + log.warning("推送执行错误") + return 0 else: log.info("推送完毕......") - return 0 + return 1 if __name__ == "__main__": - push(0, '推送正文') - + push(0, f'推送验证{int(time.time())}') From dec7a6d0650332cf849bca7a95af5a71e3fac689 Mon Sep 17 00:00:00 2001 From: TingHsi Date: Mon, 9 May 2022 00:52:11 +0800 Subject: [PATCH 39/45] =?UTF-8?q?=E9=92=89=E9=92=89=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E9=85=8D=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: TingHsi --- config/README.md | 8 ++++---- config/push.ini.example | 3 ++- push.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config/README.md b/config/README.md index 70c1e14..924a195 100644 --- a/config/README.md +++ b/config/README.md @@ -108,9 +108,9 @@ ## dingrobot 钉钉群机器人 -[dingrobot]中的api_url填写**Webhook**地址 +**webhook**填写**Webhook**地址 -[setting]中的**push_token**用于填写**安全设置**中**加签**的密钥,此选项为可选项 +**secret**填写**安全设置**中**加签**的密钥,此选项为可选项 填写示例 @@ -118,9 +118,9 @@ [setting] enable=true push_server=dingrobot -push_token= [dingrobot] -api_url=https://oapi.dingtalk.com/robot/send?access_token=XXX +webhook=https://oapi.dingtalk.com/robot/send?access_token=XXX +secret= ``` diff --git a/config/push.ini.example b/config/push.ini.example index 4d99f60..c139ea4 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -27,4 +27,5 @@ api_url=https://api2.pushdeer.com token= [dingrobot] -api_url=https://oapi.dingtalk.com/robot/send?access_token=XXX \ No newline at end of file +webhook=https://oapi.dingtalk.com/robot/send?access_token=XXX +secret= \ No newline at end of file diff --git a/push.py b/push.py index 9b14b48..ec4aca2 100644 --- a/push.py +++ b/push.py @@ -105,8 +105,8 @@ def pushdeer(status, push_message): # 钉钉群机器人 def dingrobot(status, push_message): - api_url = cfg.get('dingrobot', 'api_url') # https://oapi.dingtalk.com/robot/send?access_token=XXX - secret = cfg.get('setting', 'push_token') # 安全设置 -> 加签 -> 密钥 + api_url = cfg.get('dingrobot', 'webhook') # https://oapi.dingtalk.com/robot/send?access_token=XXX + secret = cfg.get('dingrobot', 'secret') # 安全设置 -> 加签 -> 密钥 -> SEC* if secret: timestamp = str(round(time.time() * 1000)) From da1d006b1e0fede8b5a1851a45503f2ec3015e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=9D=E3=82=89?= Date: Mon, 9 May 2022 09:07:50 +0800 Subject: [PATCH 40/45] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Bark=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/push.ini.example | 6 +++++- push.py | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/config/push.ini.example b/config/push.ini.example index c139ea4..39f51b3 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -28,4 +28,8 @@ token= [dingrobot] webhook=https://oapi.dingtalk.com/robot/send?access_token=XXX -secret= \ No newline at end of file +secret= + +[bark] +api_url=https://api.day.app +token=ssXXX diff --git a/push.py b/push.py index ec4aca2..c492d23 100644 --- a/push.py +++ b/push.py @@ -128,6 +128,12 @@ def dingrobot(status, push_message): ).json() log.info(f"推送结果:{rep.get('errmsg')}") +# Bark +def bark(status, push_message): + http.get( + url=f'{cfg.get("bark", "api_url")}/{cfg.get("bark", "token")}/{title(status)}/{push_message}' + ) + def push(status, push_message): if not load_config(): return 0 From 89f225ede68b2b381f77b9443d6fe8bfe988ffbf Mon Sep 17 00:00:00 2001 From: TingHsi Date: Mon, 9 May 2022 11:29:35 +0800 Subject: [PATCH 41/45] =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AEtouser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 企业微信支持设置touser 2. 修订config的README --- config.py | 11 +++++++++++ config/README.md | 26 ++++++++++++++++++++++++++ config/push.ini.example | 8 +++++--- push.py | 23 ++++++++++++++++------- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/config.py b/config.py index de27cc2..0d1a799 100644 --- a/config.py +++ b/config.py @@ -130,3 +130,14 @@ def clear_cookies(): else: log.info("Cookie删除完毕") f.close() + +if __name__ == "__main__": + # 初始化配置文件 + # try: + # account_cookie = config['account']['cookie'] + # config = load_config() + # config['account']['cookie'] = account_cookie + # except OSError: + # pass + # save_config() + pass \ No newline at end of file diff --git a/config/README.md b/config/README.md index 924a195..004aed4 100644 --- a/config/README.md +++ b/config/README.md @@ -105,6 +105,32 @@ * push_server 可选范围 cqhttp ftqq(sever酱) pushplus telegram dingrobot +## Wecom +企业微信 + +**wechat_id**填写**企业ID**,见: 我的企业 -> 企业设置 -> 企业ID + +**agentid**填写**AgentId**,见: 应用管理 -> 自建 -> 「你自己的应用」 -> 复制数字 +**secret**填写**Secret**,见: 应用管理 -> 自建 -> 「你自己的应用」-> 点查看链接 + +**touser**填写**接收人**,默认 @all 通知企业内所有人,指定接收人时使用大驼峰拼音,多个可用|隔开 + +填写示例 + +```ini +[setting] +enable=true +push_server=wecom + +[wecom] +#企业微信的corpid +wechat_id= +#企业微信的应用配置 +agentid= +secret= +touser=@all +``` + ## dingrobot 钉钉群机器人 diff --git a/config/push.ini.example b/config/push.ini.example index c139ea4..07c8047 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -1,6 +1,6 @@ [setting] enable=false -#共有 cqhttp ftqq(sever酱) pushplus telegram dingrobot +#共有 cqhttp ftqq(sever酱) pushplus telegram wecom dingrobot push_server=cqhttp #server酱 pushplus dingrobot 的推送token push_token=123456 @@ -17,10 +17,12 @@ bot_token=123465:abcdefg chat_id=123456 [wecom] -#企业微信的appid +#企业微信的corpid +wechat_id= +#企业微信的应用配置 agentid= secret= -wechat_id= +touser=@all [pushdeer] api_url=https://api2.pushdeer.com diff --git a/push.py b/push.py index ec4aca2..fc8b8f0 100644 --- a/push.py +++ b/push.py @@ -77,17 +77,26 @@ def cqhttp(status, push_message): # 企业微信 感谢linjie5492@github def wecom(status, push_message): secret = cfg.get('wecom', 'secret') - wechat_id = cfg.get('wecom', 'wechat_id') + corpid = cfg.get('wecom', 'wechat_id') + try: + touser = cfg.get('wecom', 'touser') + except: + # 没有配置时赋默认值 + touser = '@all' + push_token = http.post( - url=f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={wechat_id}&corpsecret={secret}', - data="").json()['access_token'] + url=f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={secret}', + data="" + ).json()['access_token'] push_data = { "agentid": cfg.get('wecom', 'agentid'), "msgtype": "text", - "touser": "@all", + "touser": touser, "text": { "content": title(status) + "\r\n" + push_message - }, "safe": 0} + }, + "safe": 0 + } http.post(f'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={push_token}', json=push_data) @@ -144,8 +153,8 @@ def push(status, push_message): # eval(push_server[:10] + "(status, push_message)") # 与面代码等效 20220508 func(status, push_message) - except: - log.warning("推送执行错误") + except Exception as r: + log.warning(f"推送执行错误:{str(r)}") return 0 else: log.info("推送完毕......") From 4194fbabf16993c5e629f0c2a6d3d680303ec61e Mon Sep 17 00:00:00 2001 From: TingHsi Date: Mon, 9 May 2022 14:33:59 +0800 Subject: [PATCH 42/45] =?UTF-8?q?=E8=AE=B0=E5=BD=95bark=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- push.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/push.py b/push.py index 3b544d6..25b831a 100644 --- a/push.py +++ b/push.py @@ -139,9 +139,10 @@ def dingrobot(status, push_message): # Bark def bark(status, push_message): - http.get( + rep = http.get( url=f'{cfg.get("bark", "api_url")}/{cfg.get("bark", "token")}/{title(status)}/{push_message}' - ) + ).json() + log.info(f"推送结果:{rep.get('message')}") def push(status, push_message): if not load_config(): From 57ae78e4dbd5139ab23a87468bd225356e6fec0a Mon Sep 17 00:00:00 2001 From: TingHsi Date: Mon, 9 May 2022 14:46:05 +0800 Subject: [PATCH 43/45] =?UTF-8?q?=E5=AE=8C=E5=96=84bark=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- config/README.md | 28 +++++++++++++++++++++++++++- config/push.ini.example | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2bffaaa..63059dd 100644 --- a/.gitignore +++ b/.gitignore @@ -138,4 +138,5 @@ dmypy.json config/*.json # push配置 -config/push.ini \ No newline at end of file +config/push.ini +.DS_Store diff --git a/config/README.md b/config/README.md index 004aed4..87bb82c 100644 --- a/config/README.md +++ b/config/README.md @@ -102,7 +102,7 @@ # push.ini配置教程 -* push_server 可选范围 cqhttp ftqq(sever酱) pushplus telegram dingrobot +* push_server 可选范围 cqhttp ftqq(sever酱) pushplus telegram dingrobot bark ## Wecom @@ -150,3 +150,29 @@ webhook=https://oapi.dingtalk.com/robot/send?access_token=XXX secret= ``` + + +## bark + +一款开源的消息推送工具 https://github.com/Finb/Bark + +手机安装bark客户端获得托管在api.day.app的Token,也可以自己搭建私有服务端。 + +**api_url**一般不用改,自己搭建私有服务端的需要改掉 + +**token**填写**APP**内**URL**中的密钥,此选项必填 + +> `https://api.day.app/` `token部分` `/Title/NotificationContent` + +填写示例 + +```ini +[setting] +enable=true +push_server=bark + +[bark] +api_url=https://api.day.app +token=XXX +``` + diff --git a/config/push.ini.example b/config/push.ini.example index bae9d17..466eba4 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -1,6 +1,6 @@ [setting] enable=false -#共有 cqhttp ftqq(sever酱) pushplus telegram wecom dingrobot +#共有 cqhttp ftqq(sever酱) pushplus telegram wecom dingrobot bark push_server=cqhttp #server酱 pushplus dingrobot 的推送token push_token=123456 From 22312052ce3a76297f83e0b8c0a795a2a64556b0 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Mon, 9 May 2022 22:17:57 +0800 Subject: [PATCH 44/45] readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0129868..a096b7b 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,8 @@ requests: [github](https://github.com/psf/requests) [pypi](https://pypi.org/proj httpx: [github](https://github.com/encode/httpx) [pypi](https://pypi.org/project/httpx/) +crontab: [github](https://github.com/josiahcarlson/parse-crontab) [pypi](https://pypi.org/project/crontab/) + ## 关于使用 Github Actions 运行 本项目**不支持**也**不推荐**使用`Github Actions`来每日自动执行! @@ -141,7 +143,7 @@ httpx: [github](https://github.com/encode/httpx) [pypi](https://pypi.org/project ## Stargazers over time -![Stargazers over time](https://starchart.cc/Womsxd/AutoMihoyoBBS.svg) +[![Stargazers over time](https://starchart.cc/Womsxd/AutoMihoyoBBS.svg)](https://starchart.cc/Womsxd/AutoMihoyoBBS) ## License From 5623502c6a9d3248812d7c31400c1613dc45be53 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Fri, 13 May 2022 10:12:29 +0800 Subject: [PATCH 45/45] Rename pylint.yml-off to pylint.yml --- .github/workflows/{pylint.yml-off => pylint.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{pylint.yml-off => pylint.yml} (100%) diff --git a/.github/workflows/pylint.yml-off b/.github/workflows/pylint.yml similarity index 100% rename from .github/workflows/pylint.yml-off rename to .github/workflows/pylint.yml