mirror of
https://github.com/hex-ci/smzdm_script.git
synced 2026-02-03 02:24:41 +08:00
update
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
[user.A]
|
||||
USER_AGENT = ""
|
||||
ANDROID_COOKIE = ""
|
||||
SK = ""
|
||||
TOKEN = ""
|
||||
|
||||
[user.B]
|
||||
USER_AGENT = ""
|
||||
ANDROID_COOKIE = ""
|
||||
SK = ""
|
||||
TOKEN = ""
|
||||
@@ -1,4 +1 @@
|
||||
APScheduler==3.10.0
|
||||
prettytable==3.6.0
|
||||
requests==2.28.2
|
||||
toml==0.10.2
|
||||
|
||||
118
smzdm_checkin.py
118
smzdm_checkin.py
@@ -1,4 +1,6 @@
|
||||
"""
|
||||
什么值得买自动签到脚本
|
||||
项目地址: https://github.com/hex-ci/smzdm_script
|
||||
0 8 * * * smzdm_checkin.py
|
||||
const $ = new Env("什么值得买签到");
|
||||
"""
|
||||
@@ -8,32 +10,27 @@ import os
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
import prettytable as pt
|
||||
import requests
|
||||
from notify import send
|
||||
from utils.file_helper import TomlHelper
|
||||
|
||||
CURRENT_PATH = Path(__file__).parent.resolve()
|
||||
CONFIG_PATH = Path(CURRENT_PATH, "config")
|
||||
|
||||
|
||||
class SmzdmBot(object):
|
||||
KEY = "apr1$AwP!wRRT$gJ/q.X24poeBInlUJC"
|
||||
DEFAULT_USER_AGENT = "smzdm_android_V10.4.25 rv:860 (Redmi Note 3;Android10;zh)smzdmapp"
|
||||
|
||||
def __init__(self, conf_kwargs: dict):
|
||||
def __init__(self, conf_kwargs: dict, index):
|
||||
self.conf_kwargs = conf_kwargs
|
||||
self.index = index
|
||||
self.session = requests.Session()
|
||||
self.start_timestamp = int(time.time())
|
||||
self._set_header()
|
||||
|
||||
def _set_header(self):
|
||||
request_key = f"{random.randint(10000000, 100000000) * 10000000000 + self.start_timestamp}"
|
||||
headers = {
|
||||
"user-agent": self.conf_kwargs["USER_AGENT"],
|
||||
"user-agent": os.environ.get("SMZDM_USER_AGENT") or self.DEFAULT_USER_AGENT,
|
||||
"request_key": request_key,
|
||||
"cookie": self.conf_kwargs["ANDROID_COOKIE"],
|
||||
"cookie": self.conf_kwargs["COOKIE"],
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"connection": "keep-alive",
|
||||
}
|
||||
@@ -43,13 +40,13 @@ class SmzdmBot(object):
|
||||
time = self.start_timestamp * 1000
|
||||
sk = self.conf_kwargs.get("SK")
|
||||
token = self.conf_kwargs.get("TOKEN")
|
||||
sign_str = f"f=android&sk={sk}&time={time}&token={token}&v=10.4.20&weixin=1&key={self.KEY}"
|
||||
sign_str = f"f=android&sk={sk}&time={time}&token={token}&v=10.4.25&weixin=1&key={self.KEY}"
|
||||
sign = self._str_to_md5(sign_str).upper()
|
||||
data = {
|
||||
"weixin": "1",
|
||||
"captcha": "",
|
||||
"f": "android",
|
||||
"v": "10.4.20",
|
||||
"v": "10.4.25",
|
||||
"sk": sk,
|
||||
"sign": sign,
|
||||
"touchstone_event": "",
|
||||
@@ -63,8 +60,20 @@ class SmzdmBot(object):
|
||||
|
||||
def checkin(self):
|
||||
url = "https://user-api.smzdm.com/checkin"
|
||||
|
||||
if self.index > 1:
|
||||
print("延时 5 秒执行")
|
||||
time.sleep(5)
|
||||
|
||||
sep = "\n********开始账号" + str(self.index) + "********"
|
||||
print(sep + "\n", end="")
|
||||
|
||||
self.start_timestamp = int(time.time())
|
||||
self._set_header()
|
||||
data = self._data()
|
||||
|
||||
resp = self.session.post(url, data)
|
||||
|
||||
if resp.status_code == 200 and int(resp.json()["error_code"]) == 0:
|
||||
resp_data = resp.json()["data"]
|
||||
checkin_num = resp_data["daily_num"]
|
||||
@@ -73,21 +82,20 @@ class SmzdmBot(object):
|
||||
exp = resp_data["cexperience"]
|
||||
rank = resp_data["rank"]
|
||||
cards = resp_data["cards"]
|
||||
tb = pt.PrettyTable()
|
||||
tb.field_names = ["签到天数", "金币", "积分", "经验", "等级", "补签卡"]
|
||||
tb.add_row([checkin_num, gold, point, exp, rank, cards])
|
||||
print(f"\n{tb}")
|
||||
|
||||
msg = f"""⭐签到成功{checkin_num}天
|
||||
🏅金币{gold}
|
||||
🏅积分{point}
|
||||
🏅经验{exp}
|
||||
🏅等级{rank}
|
||||
🏅补签卡{cards}"""
|
||||
return msg
|
||||
🏅补签卡{cards}\n"""
|
||||
|
||||
print(msg)
|
||||
return sep + "\n" + msg
|
||||
else:
|
||||
print("Faile to sign in")
|
||||
msg = "Fail to login in"
|
||||
return msg
|
||||
print("登录失败", resp.json())
|
||||
msg += "登录失败\n"
|
||||
return sep + "\n" + msg
|
||||
|
||||
def all_reward(self):
|
||||
url = "https://user-api.smzdm.com/checkin/extra_reward"
|
||||
@@ -107,9 +115,9 @@ class SmzdmBot(object):
|
||||
]["continue_checkin_reward_show"]
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"Fail to check extra reward: {e}")
|
||||
print(f"检查额外奖励失败: {e}")
|
||||
if not continue_checkin_reward_show:
|
||||
print("No extra reward today")
|
||||
print("今天没有额外奖励")
|
||||
return
|
||||
url = "https://user-api.smzdm.com/checkin/extra_reward"
|
||||
data = self._data()
|
||||
@@ -131,48 +139,44 @@ class SmzdmBot(object):
|
||||
|
||||
|
||||
def conf_kwargs():
|
||||
conf_kwargs = {}
|
||||
conf_kwargs = []
|
||||
|
||||
if Path.exists(Path(CONFIG_PATH, "config.toml")):
|
||||
print("Get configration from config.toml")
|
||||
conf_kwargs = TomlHelper(Path(CONFIG_PATH, "config.toml")).read()
|
||||
conf_kwargs.update({"toml_conf": True})
|
||||
elif os.environ.get("ANDROID_COOKIE", None):
|
||||
print("Get configration from env")
|
||||
conf_kwargs = {
|
||||
"USER_AGENT": os.environ.get("USER_AGENT"),
|
||||
"SK": os.environ.get("SK"),
|
||||
"ANDROID_COOKIE": os.environ.get("ANDROID_COOKIE"),
|
||||
"TOKEN": os.environ.get("TOKEN"),
|
||||
}
|
||||
conf_kwargs.update({"env_conf": True})
|
||||
if os.environ["SMZDM_COOKIE"]:
|
||||
cookies = os.environ["SMZDM_COOKIE"].split("&")
|
||||
for cookie in cookies:
|
||||
try:
|
||||
token = re.findall(r"sess=(.*?);", cookie)[0]
|
||||
conf_kwargs.append({
|
||||
"SK": "1",
|
||||
"COOKIE": cookie,
|
||||
"TOKEN": token,
|
||||
})
|
||||
except:
|
||||
print("发生异常错误")
|
||||
else:
|
||||
print("Please set cookies first")
|
||||
print("请先设置 SMZDM_COOKIE 环境变量")
|
||||
sys.exit(1)
|
||||
return conf_kwargs
|
||||
|
||||
|
||||
def main(conf_kwargs):
|
||||
msg = ""
|
||||
if conf_kwargs.get("toml_conf"):
|
||||
for i in conf_kwargs["user"]:
|
||||
try:
|
||||
bot = SmzdmBot(conf_kwargs["user"][i])
|
||||
msg += bot.checkin()
|
||||
bot.all_reward()
|
||||
bot.extra_reward()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
continue
|
||||
send("什么值得买签到", msg)
|
||||
else:
|
||||
bot = SmzdmBot(conf_kwargs)
|
||||
msg = bot.checkin()
|
||||
bot.all_reward()
|
||||
bot.extra_reward()
|
||||
send("什么值得买签到", msg)
|
||||
index = 0
|
||||
for config in conf_kwargs:
|
||||
try:
|
||||
index += 1
|
||||
bot = SmzdmBot(config, index)
|
||||
msg += bot.checkin()
|
||||
bot.all_reward()
|
||||
bot.extra_reward()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
continue
|
||||
|
||||
send("什么值得买签到", msg)
|
||||
|
||||
if msg is None or "Fail to login in" in msg:
|
||||
print("Fail the Github action job")
|
||||
print("发生异常错误")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import toml
|
||||
|
||||
class TomlHelper:
|
||||
def __init__(self, toml_filename):
|
||||
self.t_dict = dict()
|
||||
self.toml_file_path = toml_filename
|
||||
|
||||
def update(self, t_data):
|
||||
self.t_dict.update(t_data)
|
||||
return self.t_dict
|
||||
|
||||
def write(self, t_data):
|
||||
with open(self.toml_file_path, "w", encoding="utf-8") as fs:
|
||||
toml.dump(t_data, fs)
|
||||
|
||||
def read(self):
|
||||
with open(self.toml_file_path, "r", encoding="utf-8") as fs:
|
||||
t_data = toml.load(fs)
|
||||
return t_data
|
||||
|
||||
def read_str(self, s_data):
|
||||
t_data = toml.loads(s_data, _dict=dict)
|
||||
return t_data
|
||||
|
||||
def read_dict(self, dict):
|
||||
t_data = toml.dumps(dict)
|
||||
return t_data
|
||||
Reference in New Issue
Block a user