From dc6c0eae0471f5a59ed0597f09f95a1dcb985fd5 Mon Sep 17 00:00:00 2001 From: ZGGSONG Date: Mon, 20 Feb 2023 14:29:39 +0800 Subject: [PATCH] feat: basic func from config --- .gitignore | 1 + Check.py => check.py | 0 config.py | 13 +++++++++++++ config.yml.template | 2 ++ main.py | 41 +++++++++++++++++++++++------------------ requirements.txt | 3 ++- 6 files changed, 41 insertions(+), 19 deletions(-) rename Check.py => check.py (100%) create mode 100644 config.py create mode 100644 config.yml.template diff --git a/.gitignore b/.gitignore index f32e31a..6ad1d66 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ .DS_Store +*.yml \ No newline at end of file diff --git a/Check.py b/check.py similarity index 100% rename from Check.py rename to check.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..0753006 --- /dev/null +++ b/config.py @@ -0,0 +1,13 @@ +# coding:utf-8 +import yaml + + +def config(): + # 获取yaml文件路径 + yaml_path = 'config.yml' + + with open(yaml_path, 'rb') as f: + # yaml文件通过---分节,多个节组合成一个列表 + date = yaml.safe_load_all(f) + # print(list(date)) + return list(date) diff --git a/config.yml.template b/config.yml.template new file mode 100644 index 0000000..caef0bc --- /dev/null +++ b/config.yml.template @@ -0,0 +1,2 @@ +cookies: #&&分割 +bark_url: \ No newline at end of file diff --git a/main.py b/main.py index edfac17..19de629 100644 --- a/main.py +++ b/main.py @@ -1,35 +1,40 @@ from os import environ -from Check import CheckIn -from push import send_msg_serverJ , send_msg_pushplus, send_bark +from check import CheckIn +from push import send_msg_serverJ, send_msg_pushplus, send_bark +from config import config def main(): + conf = config() # 获取actions secrets配置的cookie SendKey - ck = environ["cookie"] - SendKey = environ.get('SendKey') - token = environ.get('token') - barkUrl = environ.get('barkUrl') + ck = conf[0]['cookies'] + # send_key = environ.get('SendKey') + # token = environ.get('token') + bark_url = conf[0]['bark_url'] try: - title, Text = CheckIn(ck) + title, text = CheckIn(ck) print('签到成功!') except Exception as e: print('程序出错!') title = '程序出错!' - Text = e + text = e finally: # print(title) - print(Text) + print(text) # Text = Text.replace('\n', '%0D%0A%0D%0A') - - rsp = send_msg_serverJ(SendKey, title, Text) # 推送消息,无SendKey不推送 - print(rsp) - - rsp = send_msg_pushplus(token, title, Text) # 推送消息,无token不推送 - print(rsp) - rsp = send_bark(barkUrl, title, Text) - print(rsp) + # if send_key != '': + # rsp = send_msg_serverJ(send_key, title, text) # 推送消息,无SendKey不推送 + # print(rsp) + # + # if token != '': + # rsp = send_msg_pushplus(token, title, text) # 推送消息,无token不推送 + # print(rsp) + + if bark_url != '': + rsp = send_bark(bark_url, title, text) + print(rsp) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/requirements.txt b/requirements.txt index 0086c01..47361b0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ requests==2.28.1 -pytz==2022.1 \ No newline at end of file +pytz==2022.1 +PyYAML==6.0 \ No newline at end of file