diff --git a/README.md b/README.md index a3af3abf..aad26968 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # aliyundrive-checkin - aliyundrive-checkin是一个定时自动签到的python程序 -- 2023/8/10: 推送支持微信应用图文消息、消息代理,支持获取每日任务[[@thsrite](https://github.com/thsrite)] +- 2023/8/10: 推送支持微信应用图文消息、消息代理,支持获取每日任务 [[@thsrite](https://github.com/thsrite)] - 2023/8/02: 采用linux构建,外加飞书推送支持 [[@bequt](https://github.com/bequt)] - 2023/6/12: 增加requests出错重试,使用chatgpt优化代码结构 - 2023/5/17: 增加自动领取签到奖励,显示本月签到次数 @@ -16,15 +16,13 @@ | TOKEN * | 阿里云盘Token 可以添加多个用英文逗号(,)分割 无需空格 | | SCKEY | Server酱 推送密钥 | | PUSHPLUS_TOKEN | pushplus 推送Token | - | WECOM_TOKENS | 企业微信 tokens | + | WECOM_TOKENS | 企业微信 Token | | WECOM_WEBHOOK | 企业微信 WEBHOOK | | BARK_DEVICEKEY | IOS应用Bark 推送密钥 | | FEISHU_DEVICEKEY | 飞书 推送密钥 | 以上TOKEN为阿里云盘签到必填项 推送项选择其中一个即可 也可多渠道推送 -WECOM_TOKENS: weCom_corpId, weCom_corpSecret, weCom_agentId, to_user, proxy_url (, to_user, proxy_url可选) - 3. 点击Actions -> 选择aliyundrive-checkin -> 点击Run workflow 运行即可 ### 其它设置 diff --git a/aliyundrive.py b/aliyundrive.py index ddf9b029..84aafdb6 100644 --- a/aliyundrive.py +++ b/aliyundrive.py @@ -20,7 +20,7 @@ def aliyundrive_check_in(self, token: str) -> AliyundriveInfo: signin_count=-1, message='', reward_notice='', - task='' + task_notice='' ) def handle_error(error_message: str) -> AliyundriveInfo: @@ -40,15 +40,15 @@ def handle_error(error_message: str) -> AliyundriveInfo: if not flag: return handle_error(f'get_reward error: {message}') - flag, task = self._get_task(access_token) + flag, message, reward_notice, task_notice = self._get_task(access_token) if not flag: - return handle_error(f'get_task error: {task}') + return handle_error(f'get_task error: {message}') info.success = True info.user_name = user_name info.signin_count = signin_count - info.reward_notice = message - info.task = task + info.reward_notice = reward_notice + info.task_notice = task_notice return info @@ -79,7 +79,7 @@ def _get_access_token(self, token: str) -> tuple[bool, str, str, str]: nick_name, user_name = data['nick_name'], data['user_name'] name = nick_name if nick_name else user_name access_token = data['access_token'] - return True, name, access_token, '成功获取access_token' + return True, name, access_token, '' """ 执行签到操作 @@ -106,7 +106,7 @@ def _check_in(self, access_token: str) -> tuple[bool, int, str]: success = data['success'] signin_count = data['result']['signInCount'] - return success, signin_count, '签到成功' + return success, signin_count, '' """ 获得奖励 @@ -114,7 +114,7 @@ def _check_in(self, access_token: str) -> tuple[bool, int, str]: :param token: 调用_get_access_token方法返回的access_token :param sign_day: 领取第几天 :return tuple[0]: 是否成功 - :return tuple[1]: message 奖励信息或者出错信息 + :return tuple[1]: message """ @retry(stop=stop_after_attempt(3), wait=wait_fixed(1)) @@ -131,16 +131,16 @@ def _get_reward(self, access_token: str, sign_day: int) -> tuple[bool, str]: return False, data['message'] success = data['success'] - notice = data['result']['notice'] - return success, notice + return success, '' """ - 今日任务 + 今日奖励/任务 :param token: 调用_get_access_token方法返回的access_token - :param sign_day: 领取第几天 :return tuple[0]: 是否成功 - :return tuple[1]: message 奖励信息或者出错信息 + :return tuple[1]: message + :return tuple[2]: 奖励信息 + :return tuple[3]: 任务信息 """ @retry(stop=stop_after_attempt(3), wait=wait_fixed(1)) @@ -158,23 +158,20 @@ def _get_task(self, access_token: str) -> tuple[bool, str]: success = data['success'] signInInfos = data['result']['signInInfos'] - year, month, day = time.localtime()[:3] - - task_str = "" - for info in signInInfos: - if int(info['day']) == day: - rewards = info['rewards'] - - for reward in rewards: - name = reward['name'] - remind = reward['remind'] - type = reward['type'] - if type == "dailySignIn": - task_str += f' 类型:签到\n' \ - f' 要求:{remind}\n' \ - f' 奖励:{name}\n' - if type == "dailyTask": - task_str += f' 类型:任务\n' \ - f' 要求:{remind}\n' \ - f' 奖励:{name}\n' - return success, task_str + + day = time.localtime().tm_mday + rewards = filter(lambda info: int(info.get('day', 0)) == day, signInInfos) + + award_notice = '' + task_notice = '' + + for reward in next(rewards)['rewards']: + name = reward['name'] + remind = reward['remind'] + type = reward['type'] + + if type == "dailySignIn": + award_notice = name + if type == "dailyTask": + task_notice = f'{remind}({name})' + return success, '', award_notice, task_notice diff --git a/aliyundrive_info.py b/aliyundrive_info.py index 549ad9ad..deaa70bc 100644 --- a/aliyundrive_info.py +++ b/aliyundrive_info.py @@ -6,13 +6,13 @@ def __init__( signin_count: int, message: str, reward_notice: str, - task: str): + task_notice: str): self.success = success self.user_name = user_name self.signin_count = signin_count self.message = message self.reward_notice = reward_notice - self.task = task + self.task_notice = task_notice def __str__(self) -> str: message_all = '' @@ -20,8 +20,8 @@ def __str__(self) -> str: message_all = f'用户:{self.user_name}\n' \ f'签到:本月已签到{self.signin_count}次\n' \ f'奖励:{self.reward_notice}\n' \ - f'任务:\n' \ - f'{self.task}' + f'任务:{self.task_notice}' + else: message_all = f'签到失败\n错误信息:{self.message}' diff --git a/main.py b/main.py index e992b34f..42d6958f 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import logging import os import re import argparse @@ -43,8 +42,6 @@ def main(): message_all = '\n'.join(message_all) message_all = re.sub('\n+', '\n', message_all).rstrip('\n') - logging.info(message_all) - message_send = MessageSend() message_send.send_all(message_tokens, title, message_all) diff --git a/message_send.py b/message_send.py index a004e859..0a3d9f80 100644 --- a/message_send.py +++ b/message_send.py @@ -102,7 +102,7 @@ def weCom(self, tokens, title, content): { "title": title, "description": content, - "picurl": "https://raw.githubusercontent.com/thsrite/aliyundrive-checkin/main/aliyunpan.jpg", + "picurl": "https://raw.githubusercontent.com/libuke/aliyundrive-checkin/main/aliyunpan.jpg", "url": '' } ] @@ -171,24 +171,7 @@ def feishu(self, device_key, title, content): "charset": "utf-8" } - data = { - "msg_type": "post", - "content": { - "post": { - "zh_cn": { - "title": title, - "content": [ - [ - { - "tag": "text", - "text": content, - } - ] - ] - } - } - } - } + data = {"msg_type": "post", "content": {"post": {"zh_cn": {"title": title, "content": [[{"tag": "text", "text": content}]]}}}} resp = requests.post(url, headers=headers, json=data) resp_json = resp.json()