Add all_reward and extra_reward

This commit is contained in:
LuckyHunter
2023-02-25 01:40:27 +08:00
parent 2bf3496df0
commit 6cbec9245f
4 changed files with 99 additions and 22 deletions

View File

@@ -1,11 +1,18 @@
# Cookie
[user.A]
USER_AGENT = ""
ANDROID_COOKIE = ""
SK = ""
TOKEN = ""
# Notification
[user.B]
USER_AGENT = ""
ANDROID_COOKIE = ""
SK = ""
TOKEN = ""
[notify]
PUSH_PLUS_TOKEN = ""
SC_KEY = ""
TG_BOT_TOKEN = ""
TG_USER_ID = ""
TG_USER_ID = ""

View File

@@ -8,7 +8,6 @@ from pathlib import Path
import prettytable as pt
import requests
from loguru import logger
from notify.notify import NotifyBot
from utils.file_helper import TomlHelper
@@ -28,10 +27,11 @@ class SmzdmBot(object):
def _set_header(self):
request_key = f"{random.randint(10000000, 100000000) * 10000000000 + self.start_timestamp}"
headers = {
"user-agent": self.conf_kwargs.get("USER_AGENT"),
"user-agent": self.conf_kwargs["USER_AGENT"],
"request_key": request_key,
"cookie": self.conf_kwargs.get("ANDROID_COOKIE"),
"cookie": self.conf_kwargs["ANDROID_COOKIE"],
"content-type": "application/x-www-form-urlencoded",
"connection": "keep-alive",
}
self.session.headers = headers
@@ -73,7 +73,7 @@ class SmzdmBot(object):
tb.field_names = ["签到天数", "金币", "积分", "经验", "等级", "补签卡"]
tb.add_row([checkin_num, gold, point, exp, rank, cards])
logger.info(f"\n{tb}")
msg = f"""⭐签到成功{checkin_num}
msg = f"""\n⭐签到成功{checkin_num}
🏅金币{gold}
🏅积分{point}
🏅经验{exp}
@@ -85,13 +85,54 @@ class SmzdmBot(object):
msg = "Fail to login in"
return msg
def all_reward(self):
url = "https://user-api.smzdm.com/checkin/extra_reward"
data = self._data()
resp = self.session.post(url, data)
if resp.status_code == 200 and int(resp.json()["error_code"]) == 0:
logger.info(resp.json()["data"])
def main():
def extra_reward(self):
continue_checkin_reward_show = False
userdata_v2 = self._show_view_v2()
try:
for item in userdata_v2["data"]["rows"]:
if item["cell_type"] == "18001":
continue_checkin_reward_show = item["cell_data"][
"checkin_continue"
]["continue_checkin_reward_show"]
break
except Exception as e:
logger.error(f"Fail to check extra reward: {e}")
if not continue_checkin_reward_show:
logger.info("No extra reward today")
return
url = "https://user-api.smzdm.com/checkin/extra_reward"
data = self._data()
resp = self.session.post(url, data)
logger.info(resp.json()["data"])
def _show_view_v2(self):
url = "https://user-api.smzdm.com/checkin/show_view_v2"
data = self._data()
resp = self.session.post(url, data)
if resp.status_code == 200 and int(resp.json()["error_code"]) == 0:
return resp.json()
def _vip(self):
url = "https://user-api.smzdm.com/vip"
data = self._data()
resp = self.session.post(url, data)
logger.info(resp.json()["data"])
def conf_kwargs():
conf_kwargs = {}
if Path.exists(Path(CONFIG_PATH, "config.toml")):
logger.info("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):
logger.info("Get configration from env")
conf_kwargs = {
@@ -105,15 +146,36 @@ def main():
"TG_USER_ID": os.environ.get("TG_USER_ID", None),
"TG_BOT_API": os.environ.get("TG_BOT_API", None),
}
conf_kwargs.update({"env_conf": True})
else:
logger.info("Please set cookies first")
sys.exit(1)
msg = SmzdmBot(conf_kwargs).checkin()
NotifyBot(content=msg, **conf_kwargs)
if msg == "Fail to login in":
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:
logger.error(e)
continue
NotifyBot(content=msg, **conf_kwargs["notify"])
else:
bot = SmzdmBot(conf_kwargs)
msg = bot.checkin()
bot.all_reward()
bot.extra_reward()
NotifyBot(content=msg, **conf_kwargs)
if msg is None or "Fail to login in" in msg:
logger.error("Fail the Github action job")
sys.exit(1)
if __name__ == "__main__":
main()
main(conf_kwargs())

View File

@@ -71,15 +71,15 @@ class NotifyBot(object):
)
return
TG_BOT_API = self.kwargs.get("TG_BOT_API", "https://api.telegram.org")
TG_BOT_API = self.kwargs.get("TG_BOT_API", "https://api.telegram.org/")
url = urljoin(TG_BOT_API, f"/bot{TG_BOT_TOKEN}/sendMessage")
headers = {"Content-Type": "application/x-www-form-urlencoded"}
payload = {
params = {
"chat_id": str(TG_USER_ID),
"text": f"{self.title}\n\n{self.content}",
"text": f"{self.title}\n{self.content}",
"disable_web_page_preview": "true",
}
resp = requests.post(url=url, headers=headers, params=payload)
resp = requests.post(url=url, headers=headers, params=params)
if resp.status_code == 200:
logger.info("✅ Telegram Bot notified")
return resp.json()