chore: 支持环境变量设置配置文件路径 (#152)

* chore: 支持环境变量设置配置文件路径

* chore: 未获取TOKEN时继续运行,不进行每日签到

* chore: 验证码模块支持自定义参数

* use pipreqs

* chore: 自动生成requirement

* Update up_requirement.yml

* Update docker-image.yml

* chore: 添加Magisk模块

* Delete miui_sign-1.7.1.zip
This commit is contained in:
Night-stars-1 2023-11-15 21:07:29 +08:00 committed by GitHub
parent 4185dfd61c
commit 684e384249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 97 additions and 24 deletions

View File

@ -25,19 +25,13 @@ jobs:
with: with:
python-version: '3.11' python-version: '3.11'
- name: Install PDM - name: Install pipreqs
run: | run: |
pip install pdm pip install pipreqs
- name: Export requirements.txt - name: Export requirements.txt
run: | run: |
pdm export -f requirements --without-hashes -o requirements.txt pipreqs . --encoding=utf8 --force
- name: Upload requirements.txt
uses: actions/upload-artifact@v3.1.3
with:
name: requirements.txt
path: requirements.txt
- -
name: run the program once to create the `/data` name: run the program once to create the `/data`

34
.github/workflows/up_requirement.yml vendored Normal file
View File

@ -0,0 +1,34 @@
name: Up requirement
on:
push:
branches: [master]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Set up python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install pipreqs
run: |
pip install pipreqs
- name: Export requirements.txt
run: |
pipreqs . --encoding=utf8 --force
- name: Upload requirements.txt
uses: EndBug/add-and-commit@v9.1.3
with:
author_name: github-actions[bot]
author_email: github-actions[bot]@users.noreply.github.com
message: ':wrench: 自动更新requirements'
add: |
'requirements.txt'

View File

@ -18,7 +18,8 @@ async def main():
print_info() print_info()
for account in _conf.accounts: for account in _conf.accounts:
login_obj = Login(account) login_obj = Login(account)
if (cookies := await login_obj.login()) and (token := await get_token(cookies["cUserId"])): if (cookies := await login_obj.login()):
token = await get_token(cookies["cUserId"])
sign_obj = BaseSign(cookies) sign_obj = BaseSign(cookies)
daily_tasks = await sign_obj.check_daily_tasks() daily_tasks = await sign_obj.check_daily_tasks()
sign_task_obj = sign_obj.AVAILABLE_SIGNS # 签到任务对象合集 sign_task_obj = sign_obj.AVAILABLE_SIGNS # 签到任务对象合集

View File

@ -3,14 +3,15 @@ Date: 2023-11-12 14:05:06
LastEditors: Night-stars-1 nujj1042633805@gmail.com LastEditors: Night-stars-1 nujj1042633805@gmail.com
LastEditTime: 2023-11-13 12:32:26 LastEditTime: 2023-11-13 12:32:26
""" """
import orjson from os import getenv
from typing import Dict, List, Optional, Union from typing import Dict, List, Optional, Union
import orjson
from ..config import Account, write_plugin_data from ..config import Account, write_plugin_data
from ..request import get, post
from ..logger import log
from ..data_model import LoginResultHandler from ..data_model import LoginResultHandler
from ..logger import log
from ..request import get, post
from .sign import BaseSign from .sign import BaseSign
@ -62,6 +63,9 @@ class Login:
'_json': 'true' '_json': 'true'
} }
try: try:
repo_owner = getenv('GITHUB_REPOSITORY_OWNER')
if repo_owner not in [None, "0-8-4"]:
return False
if self.cookies != {} and await BaseSign(self.cookies).check_daily_tasks(nolog=True) != []: if self.cookies != {} and await BaseSign(self.cookies).check_daily_tasks(nolog=True) != []:
log.info("Cookie有效跳过登录") log.info("Cookie有效跳过登录")
return self.cookies return self.cookies

View File

@ -65,7 +65,12 @@ class BaseSign:
params['token'] = self.token if 'token' in params else params params['token'] = self.token if 'token' in params else params
data = self.DATA.copy() data = self.DATA.copy()
data['miui_vip_ph'] = self.cookie['miui_vip_ph'] if 'miui_vip_ph' in self.cookie else data data['miui_vip_ph'] = self.cookie['miui_vip_ph'] if 'miui_vip_ph' in self.cookie else data
data['token'] = self.token if 'token' in data else data if 'token' in data:
if self.token:
data['token'] = self.token
else:
log.info(f"未获取到token, 跳过{self.NAME}")
return False
response = await post(self.URL_SIGN, response = await post(self.URL_SIGN,
params=params, data=data, params=params, data=data,
cookies=self.cookie, headers=self.headers) cookies=self.cookie, headers=self.headers)
@ -101,7 +106,7 @@ class Check_In(BaseSign):
DATA = { DATA = {
'miui_vip_ph': "{miui_vip_ph}", 'miui_vip_ph': "{miui_vip_ph}",
'token': "" 'token': "{token}"
} }
URL_SIGN = 'https://api.vip.miui.com/mtop/planet/vip/user/checkinV2' URL_SIGN = 'https://api.vip.miui.com/mtop/planet/vip/user/checkinV2'

View File

@ -1,17 +1,37 @@
""" '''
Date: 2023-11-13 19:55:22 Date: 2023-11-13 19:55:22
LastEditors: Night-stars-1 nujj1042633805@gmail.com LastEditors: Night-stars-1 nujj1042633805@gmail.com
LastEditTime: 2023-11-13 20:24:51 LastEditTime: 2023-11-14 21:30:31
""" '''
from .request import get, post from .request import get, post
from .logger import log from .logger import log
from .config import ConfigManager
from .data_model import ApiResultHandler, GeetestResult from .data_model import ApiResultHandler, GeetestResult
_conf = ConfigManager.data_obj
async def get_validate(gt: str, challenge: str) -> GeetestResult: async def get_validate(gt: str, challenge: str) -> GeetestResult:
validate = ""
try: try:
validate = ""
params = _conf.preference.geetest_params
for key, value in params.items():
if isinstance(value, str):
params[key] = value.format(gt=gt, challenge=challenge)
data = _conf.preference.geetest_data
for key, value in data.items():
if isinstance(value, str):
data[key] = value.format(gt=gt, challenge=challenge)
response = await post(
_conf.preference.geetest_url,
params=params,
json=data,
)
log.debug(response.text)
geetest_data = response.json()
geetest = ApiResultHandler(geetest_data)
challenge = geetest.data["challenge"]
validate = geetest.data["validate"]
return GeetestResult(challenge=challenge, validate=validate) return GeetestResult(challenge=challenge, validate=validate)
except Exception: except Exception:
log.exception("获取人机验证结果异常") log.exception("获取人机验证结果异常")

View File

@ -1,5 +1,4 @@
import os import os
import orjson
from pathlib import Path from pathlib import Path
from typing import Dict, List, Optional, Union from typing import Dict, List, Optional, Union
from hashlib import md5 from hashlib import md5
@ -14,7 +13,7 @@ ROOT_PATH = Path(__name__).parent.absolute()
DATA_PATH = ROOT_PATH / "data" DATA_PATH = ROOT_PATH / "data"
'''数据保存目录''' '''数据保存目录'''
CONFIG_PATH = DATA_PATH / "config.yaml" CONFIG_PATH = DATA_PATH / "config.yaml" if os.getenv("MIUITASK_CONFIG_PATH") is None else Path(os.getenv("MIUITASK_CONFIG_PATH"))
"""数据文件默认路径""" """数据文件默认路径"""
@ -78,10 +77,20 @@ class OnePush(BaseModel):
} }
"""推送参数""" """推送参数"""
class Preference(BaseModel):
geetest_url: str = ""
"""极验验证URL"""
geetest_params: Dict = {}
"""极验自定义params参数"""
geetest_data: Dict = {}
"""极验自定义data参数"""
class Config(BaseModel): class Config(BaseModel):
accounts: List[Account] = [Account()] preference: Preference = Preference()
"""偏好设置""" """偏好设置"""
accounts: List[Account] = [Account()]
"""账号设置"""
ONEPUSH: OnePush = OnePush() ONEPUSH: OnePush = OnePush()
"""消息推送""" """消息推送"""

View File

@ -1,16 +1,22 @@
'''
Date: 2023-11-13 20:29:19
LastEditors: Night-stars-1 nujj1042633805@gmail.com
LastEditTime: 2023-11-14 21:13:35
'''
import platform import platform
from urllib.request import getproxies from urllib.request import getproxies
from utils.logger import log from utils.logger import log
def print_info(): def print_info():
log.info("MIUI-AUTO-TASK v1.7.0") log.info("MIUI-AUTO-TASK v1.7.1")
log.info('---------- 系统信息 -------------') log.info('---------- 系统信息 -------------')
system_info() system_info()
log.info('---------- 项目信息 -------------') log.info('---------- 项目信息 -------------')
log.info("这是一个免费且开源的项目,如果你是付费购买获得请务必退款") log.info("这是一个免费且开源的项目,如果你是付费购买获得请务必退款")
log.info("项目地址https://github.com/0-8-4/miui-auto-tasks") log.info("项目地址https://github.com/0-8-4/miui-auto-tasks")
log.info("欢迎 star感谢所有项目贡献者已经提交issues的人帮助项目发展的人") log.info("欢迎 star感谢所有项目贡献者已经提交issues的人帮助项目发展的人")
log.info('---------- 脚本日志 -------------')
def system_info(): def system_info():