diff --git a/check.py b/check.py index 93f1674..383284e 100644 --- a/check.py +++ b/check.py @@ -38,8 +38,9 @@ def CheckIn(cookie): mess = checkin.json()['message'] time = state.json()['data']['leftDays'] + email = state.json()['data']['email'] days = time.split('.')[0] - msg = f'现在时间是:{time_now}\ncheckin: {checkin.status_code} | state: {state.status_code}\n{mess}\n剩余天数:{days}天' + msg = f'现在时间是:{time_now}\nemail: {email}\ncheckin: {checkin.status_code} | state: {state.status_code}\n{mess}\n剩余天数:{days}天' checkin.close() state.close() diff --git a/config.py b/config.py index 0753006..da2f6cc 100644 --- a/config.py +++ b/config.py @@ -2,12 +2,17 @@ import yaml +# https://blog.csdn.net/weixin_41010198/article/details/111591030 def config(): # 获取yaml文件路径 yaml_path = 'config.yml' + # 使用open()函数读取config.yaml文件 + yaml_file = open(yaml_path, "r", encoding="utf-8") + # 读取文件中的内容 + file_data = yaml_file.read() + # print(f"file_date type: {type(file_data)}\nfile_date value:\n{file_data}") + yaml_file.close() - with open(yaml_path, 'rb') as f: - # yaml文件通过---分节,多个节组合成一个列表 - date = yaml.safe_load_all(f) - # print(list(date)) - return list(date) + # 加载数据流,返回字典类型数据 + y = yaml.load(file_data, Loader=yaml.FullLoader) + return y diff --git a/config.yml.template b/config.yml.template index caef0bc..b8253f8 100644 --- a/config.yml.template +++ b/config.yml.template @@ -1,2 +1,5 @@ -cookies: #&&分割 -bark_url: \ No newline at end of file +cookies: + - #多cookie +bark_url: # bark app中的URL +send_key: # 将Server酱中的SendKey复制到此 +token: # 将push plus微信公众号中的token复制到此 \ No newline at end of file diff --git a/main.py b/main.py index 19de629..257316e 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -from os import environ from check import CheckIn from push import send_msg_serverJ, send_msg_pushplus, send_bark from config import config @@ -6,34 +5,35 @@ from config import config def main(): conf = config() - # 获取actions secrets配置的cookie SendKey - ck = conf[0]['cookies'] - # send_key = environ.get('SendKey') - # token = environ.get('token') - bark_url = conf[0]['bark_url'] - try: - title, text = CheckIn(ck) - print('签到成功!') - except Exception as e: - print('程序出错!') - title = '程序出错!' - text = e - finally: - # print(title) - print(text) - # Text = Text.replace('\n', '%0D%0A%0D%0A') - - # 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) + ck = conf['cookies'] + send_key = conf['send_key'] + token = conf['token'] + bark_url = conf['bark_url'] + + for c in ck: + try: + title, text = CheckIn(c) + print('签到成功!') + except Exception as e: + print('程序出错!') + title = '程序出错!' + text = e + finally: + # print(title) + print(text) + # Text = Text.replace('\n', '%0D%0A%0D%0A') + + 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__':