Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增添两条通知渠道【PushDeer,wxPusher】 #366

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,38 @@
</div>
</div>


## 如何使用本仓库内容

在青龙创建一个订阅

拉库命令 `ql repo https://github.com/Fansirsqi/dailycheckin.git null null null main`

配置执行后运行的命令
`pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && pip install requests pycrypto pycryptodome && cd /ql/data/repo/Fansirsqi_dailycheckin_main && python setup.py develop`

在脚本管理根目录创建`config.json`配置文件可以参考官方配置,这里只是增加了一段

[配置示例](https://gist.githubusercontent.com/Fansirsqi/9e238bb3e432fdb7bee1caa46da81519/raw/5a7d599b526564c68b0120e9a275ce6f414757df/config.json)

```
,
"TESTNOTICE": [
{
"test1": "test1mesg"
}
]
```
强烈建议您在`https://www.json.cn/`这个网站检查您的配置

最后在定时任务里创建一个测试任务

`task dailycheckin --include TESTNOTICE`运行并查看日志

![1715763862230.png](https://pic2.ziyuan.wang/user/fansir/2024/05/1715763862230_5344cb6724871.png)

![1715763931708.png](https://pic2.ziyuan.wang/user/fansir/2024/05/1715763931708_ec7c766df87c4.png)

## ✨ 特性

- 📦 支持 Pypi 包安装
Expand Down Expand Up @@ -65,6 +97,27 @@

## 💬 通知列表

- [PushDeer](https://www.pushdeer.com/)
- [wxPusher](https://wxpusher.zjiecode.com/docs/#/)

> [PushDeer预览](https://pic2.ziyuan.wang/user/fansir/2024/05/1715593565981_39b4eff978354.png)
>
> [wxPusher预览](https://pic2.ziyuan.wang/user/fansir/2024/05/1715593114657_e53ec9acf7e1e.png)
>
> 新增以上渠道配置如下

```json
{
"PUSHKEY": "", //PushDeer 的 pushkey
"WXPUSHER_TK": "", //wxpusher_token
"WXPUSHER_UID": "", //wxpusher_uid
//以上是新增内容
"BARK_URL": "",
...
}
```


- dingtalk(钉钉)
- 企业微信群机器人(企业微信)
- 企业微信应用消息(企业微信)
Expand Down
3 changes: 3 additions & 0 deletions dailycheckin/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def checkin_map():
checkin_map = checkin_map()

notice_map = {
"PUSHKEY": "",
"WXPUSHER_TK": "",
"WXPUSHER_UID": "",
"BARK_URL": "",
"COOLPUSHEMAIL": "",
"COOLPUSHQQ": "",
Expand Down
33 changes: 8 additions & 25 deletions dailycheckin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ def check_config(task_list):
for one_check, _ in checkin_map.items():
if one_check in task_list:
if _check_info.get(one_check.lower()):
for _, check_item in enumerate(
_check_info.get(one_check.lower(), [])
):
if "xxxxxx" not in str(check_item) and "多账号" not in str(
check_item
):
for _, check_item in enumerate(_check_info.get(one_check.lower(), [])):
if "xxxxxx" not in str(check_item) and "多账号" not in str(check_item):
if one_check.lower() not in check_info.keys():
check_info[one_check.lower()] = []
check_info[one_check.lower()].append(check_item)
Expand All @@ -63,16 +59,13 @@ def check_config(task_list):
print(e)
return False, False
else:
print(
"未找到 config.json 配置文件\n请在下方任意目录中添加「config.json」文件:\n"
+ "\n".join(config_path_list)
)
print("未找到 config.json 配置文件\n请在下方任意目录中添加「config.json」文件:\n" + "\n".join(config_path_list))
return False, False


def checkin():
start_time = time.time()
utc_time = (datetime.utcnow() + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S")
utc_time = (datetime.now() + timedelta(hours=8)).strftime("%Y-%m-%d %H:%M:%S") # update: Deprecated since version 3.12: Use datetime.now() with UTC instead.
print(f"当前时间: {utc_time}\n当前版本: {__version__}")
args = parse_arguments()
include = args.include
Expand All @@ -88,12 +81,7 @@ def checkin():
task_list = list(set(include) - set(exclude))
notice_info, check_info = check_config(task_list)
if check_info:
task_name_str = "\n".join(
[
f"「{checkin_map.get(one.upper())[0]}」账号数 : {len(value)}"
for one, value in check_info.items()
]
)
task_name_str = "\n".join([f"「{checkin_map.get(one.upper())[0]}」账号数 : {len(value)}" for one, value in check_info.items()])
print(f"\n---------- 本次执行签到任务如下 ----------\n\n{task_name_str}\n\n")
content_list = []
for one_check, check_list in check_info.items():
Expand All @@ -111,18 +99,13 @@ def checkin():
try:
url = "https://pypi.org/pypi/dailycheckin/json"
latest_version = requests.get(url=url, timeout=30).json()["info"]["version"]
except:
except: # noqa: E722
print("获取最新版本失败")
latest_version = "0.0.0"
content_list.append(
f"开始时间: {utc_time}\n"
f"任务用时: {int(time.time() - start_time)} 秒\n"
f"当前版本: {__version__}\n"
f"最新版本: {latest_version}\n"
f"项目地址: https://github.com/Sitoi/dailycheckin"
)
content_list.append(f"开始时间: {utc_time}\n" f"任务用时: {int(time.time() - start_time)} 秒\n" f"当前版本: {__version__}\n" f"最新版本: {latest_version}\n" f"项目地址: https://github.com/Sitoi/dailycheckin")
push_message(content_list=content_list, notice_info=notice_info)
return
# push_message(content_list=content_list, notice_info=notice_info)


if __name__ == "__main__":
Expand Down
Empty file added dailycheckin/test/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions dailycheckin/test/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from dailycheckin import CheckIn
import os
import json


class TestNotice(CheckIn):
name = "通知测试"

def __init__(self, check_item):
self.check_item = check_item

def main(self):
return f"测试内容{self.check_item}"


if __name__ == "__main__":
with open(
os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.json"),
encoding="utf-8",
) as f:
datas = json.loads(f.read())
_check_item = datas.get("TestNotice", [])[0]
print(TestNotice(check_item=_check_item).main())
Loading