本帖最后由 culprit 于 2021-2-2 21:24 编辑
往期云函数
【修改版】腾讯云函数实现每日天气推送:https://www.52pojie.cn/thread-1270946-1-1.html
【云函数】每日推送舔狗日记:https://www.52pojie.cn/thread-1271888-1-1.html
【云函数】什么值得买超值优惠推送 :https://www.52pojie.cn/thread-1359554-1-1.html
云函数部署教程:
1.绑定自己的推送机器人,使用GitHub账号登陆即可
(1)server酱(支持微信推送):https://sc.ftqq.com/3.version
(2)coolpush(支持QQ推送、微信推送):https://cp.xuthus.cc/
(3)Qmsg酱 -- 推荐用这个,比较稳定(支持QQ推送):https://qmsg.zendee.cn/
2.登录腾讯云函数,选择新建
3.选择自定义创建,输入函数名称,运行环境选择Python3
4.选择在线编辑,输入入口函数名(重点),粘贴函数代码(图中马赛克机器人的key需自行修改,选择其一即可,不然无法使用)
5.进入函数代码,测试是否可以正常运行
6.创建触发器(云函数定时执行),何时触发可以自己修改,图中为例子
7.执行结果
函数代码:
[Python] 纯文本查看 复制代码 import requests,random,json
url = "https://c.m.163.com/ug/api/wuhan/app/data/list-total"
server_key = 'xxxxx'
coolpush_key = 'xxxxx'
qmsg_key = 'xxxxxx'
def UserAgent(): #随机获取请求头
user_agent_list = ['Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.3319.102 Safari/537.36',
'Mozilla/5.0 (X11; CrOS i686 3912.101.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36',
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:17.0) Gecko/20100101 Firefox/17.0.6',
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2224.3 Safari/537.36',
'Mozilla/5.0 (X11; CrOS i686 3912.101.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36']
UserAgent={'User-Agent': random.choice(user_agent_list)}
return UserAgent
def Get_Url(arg1,arg2):
url_json = requests.get(url=url,headers=UserAgent()).json()
today_confirm = str(url_json['data']['chinaTotal']['today']['confirm'])#全国累计确诊较昨日新增
today_input =str(url_json['data']['chinaTotal']['today']['input'])#全国较昨日新增境外输入
today_storeConfirm = str(url_json['data']['chinaTotal']['today']['storeConfirm'])#全国现有确诊较昨日
today_dead =str(url_json['data']['chinaTotal']['today']['dead'])#累计死亡较昨日新增
today_heal = str(url_json['data']['chinaTotal']['today']['heal'])#累计治愈较昨日新增
today_incrNoSymptom = str(url_json['data']['chinaTotal']['extData']['incrNoSymptom'])#无症状感染者较昨日
total_confirm = str(url_json['data']['chinaTotal']['total']['confirm']) # 全国累计确诊
total_input = str(url_json['data']['chinaTotal']['total']['input']) # 境外输入
total_dead = str(url_json['data']['chinaTotal']['total']['dead']) # 累计死亡
total_heal = str(url_json['data']['chinaTotal']['total']['heal']) # 累计治愈
total_storeConfirm = str(url_json['data']['chinaTotal']['total']['confirm'] - url_json['data']['chinaTotal']['total']['dead'] - url_json['data']['chinaTotal']['total']['heal']) # 全国现有确诊
total_noSymptom = str(url_json['data']['chinaTotal']['extData']['noSymptom'])#无症状感染者
lastUpdateTime = url_json['data']['lastUpdateTime']#截止时间
data ='-' * 8 +'全国疫情数据实时统计' + '-' * 8 + '\n统计截至时间:'+ lastUpdateTime +'\n' + '-' * 32 + '\n' + \
' 累计确诊:' + total_confirm + ' ; ' + '较昨日:' + today_confirm + \
'\n 现有确诊:' + total_storeConfirm + ' ; ' + '较昨日:' + today_storeConfirm + \
'\n 累计死亡:' + total_dead + ' ; ' + '较昨日:' + today_dead + \
'\n 累计治愈:' + total_heal + ' ; ' + '较昨日:' + today_heal + \
'\n 境外输入:' + total_input + ' ; ' + '较昨日:' + today_input + \
'\n 无症状感染者:' + total_noSymptom + ' ; ' + '较昨日:' + today_incrNoSymptom
print(data)
select_robots(0,data) #0为Qmsg推送,1为酷推推送,2为server酱推送。默认为0
def select_robots(i,data):
if i == 0:
HtmlPuch_Qmsg(data)
elif i == 1:
HtmlPuch_coolpush(data)
elif i == 2:
HtmlPuch_server(data)
else:
print('选择错误!')
def HtmlPuch_server(data): #server酱推送
url_key = "https://sc.ftqq.com/" + server_key + ".send"
push_data = {'text':"全国疫情数据实时统计",'desp':data}
html = requests.post(url_key,headers=UserAgent(),data=push_data)
def HtmlPuch_coolpush(data): #酷推推送
url_key = "https://push.xuthus.cc/send/" + coolpush_key
push_data = {'c':data}
html = requests.get(url=url_key,params=push_data,headers=UserAgent())
def HtmlPuch_Qmsg(data): #Qmsg推送
url_key = "https://qmsg.zendee.cn/send/" + qmsg_key
push_data = {'msg':data}
html = requests.get(url=url_key,params=push_data,headers=UserAgent())
@hack78
|