借助群晖定时推送各类通知/热点到微信

前提,能看得懂python代码。。。Ps,我也是小白。

场景应用

IT资讯热榜推送到微信

WxPusher微信推送服务

WxPusher (微信推送服务)是一个使用微信公众号作为通道的,实时信息推送平台,你可以通过调用API的方式,把信息推送到微信上,无需安装额外的软件,即可做到信息实时通知。 你可以使用WxPusher来做服务器报警通知、抢课通知、抢票通知,信息更新提示等。

手册说明:https://wxpusher.zjiecode.com/docs

管理后台:https://wxpusher.zjiecode.com/admin/

Python代码

  • 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

至此,结束。

THE END
分享
二维码
打赏
海报
<<上一篇
下一篇>>