借助群晖定时推送各类通知/热点到微信
前提,能看得懂python代码。。。Ps,我也是小白。
场景应用
将IT资讯热榜推送到微信
- IT资讯热榜API:GET https://api.vvhan.com/api/hotlist/itNews
- 更多API可参考:https://api.vvhan.com/
- 也可从官方或其他渠道获取到API地址
WxPusher微信推送服务
WxPusher (微信推送服务)是一个使用微信公众号作为通道的,实时信息推送平台,你可以通过调用API的方式,把信息推送到微信上,无需安装额外的软件,即可做到信息实时通知。 你可以使用WxPusher来做服务器报警通知、抢课通知、抢票通知,信息更新提示等。
手册说明:https://wxpusher.zjiecode.com/docs
管理后台:https://wxpusher.zjiecode.com/admin/
Python代码
- appToken
- 打开应用的后台https://wxpusher.zjiecode.com/admin/,从左侧菜单栏,找到appToken菜单,在这里,你可以重置appToken,请注意,重置后,老的appToken会立即失效,调用接口会失败。
- UID获取
- 将下述代码保存在群晖中
- 比如:
/volume1/docker/python/itNews.py
- 比如:
- import json
- import requests
-
- def wxpusher(contenthtml, summary):
- '''
- WxPusher微信推送服务
- :param contenthtml:html内容(只发送body标签内部的数据即可,不包括body标签)
- :param summary:消息摘要
- :return:
- '''
- posturl = 'https://wxpusher.zjiecode.com/api/send/message'
- postcs = {
- "appToken": "AT_XXXXX",
- "content": contenthtml,
- "summary": summary,
- "contentType": 2,
- "uids": ["UID_XXXX","UID_XXXXXX"],
- "url": "https://www.chillifish.cn",
- "verifyPay": False
- }
- postheader = {'Content-Type': 'application/json'}
- try:
- postres = requests.post(posturl, data=json.dumps(postcs), headers=postheader)
- if postres.status_code == 200:
- print("POST请求成功,响应内容:")
- print(postres.text)
- else:
- print("POST请求失败,状态码:", postres.status_code)
- except requests.exceptions.RequestException as e:
- print("接口异常:", e)
-
- def itNews():
- '''
- IT资讯热榜API
- :return:
- '''
- geturl = 'https://api.vvhan.com/api/hotlist/itNews'
- res = requests.get(geturl)
- contenthtml = ['IT资讯热榜API:<br/>']
- try:
- if res.status_code == 200:
- resdata = res.json()['data']
- for data in resdata:
- contenthtml.append(f"<a href={data['mobilUrl']}>{data['index']}、{data['title']} </a><br/>")
- wxpusher(''.join(contenthtml), 'IT资讯热榜API')
- else:
- print('接口异常', '接口异常')
- except requests.exceptions.RequestException as e:
- print(e, '接口异常')
-
- itNews()
-
群晖设置自动任务
控制面板--》任务计划--》新增--》计划的任务--》用户定义的脚本
- 常规、计划根据自己想法自行设置
- 任务设置
- 运行命令:
python /volume1/docker/python/itNews.py
- 运行命令:
至此,结束。
共有 0 条评论