Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
libuke committed Aug 10, 2023
1 parent d7279d2 commit 89fc76e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 63 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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: 增加自动领取签到奖励,显示本月签到次数
Expand All @@ -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 运行即可

### 其它设置
Expand Down
63 changes: 30 additions & 33 deletions aliyundrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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, ''

"""
执行签到操作
Expand All @@ -106,15 +106,15 @@ 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, ''

"""
获得奖励
: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))
Expand All @@ -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))
Expand All @@ -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
8 changes: 4 additions & 4 deletions aliyundrive_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ 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 = ''
if self.success:
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}'

Expand Down
3 changes: 0 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os
import re
import argparse
Expand Down Expand Up @@ -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)

Expand Down
21 changes: 2 additions & 19 deletions message_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": ''
}
]
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 89fc76e

Please sign in to comment.