[Python] 【云函数】全国疫情数据实时统计(包含部署教程)



[Python] 【云函数】全国疫情数据实时统计(包含部署教程)

特别声明:本站资源分别为免费资源、查看密码或解压密码资源、三个级别VIP会员资源。本站所有发布的内容都是安全,请放心下载!本站不可能所有资源都可以商业用途,原创或部分除外!如:商业用途请联系原作者购买正版。与本站无关!若侵犯到您的权益,请联系本站删除,我们将及时处理!

分享

云函数部署教程:
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.执行结果



函数代码:

 

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())
分享到:
打赏
未经允许不得转载:

作者: cj13888, 转载或复制请以 超链接形式 并注明出处 易启发资源网
原文地址: 《[Python] 【云函数】全国疫情数据实时统计(包含部署教程)》 发布于2021-4-5

评论


切换注册

登录

忘记密码?

您也可以使用第三方帐号快捷登录

切换登录

注册

[Python] 【云函数】全国疫情数据实时统计(包含部署教程)

长按图片转发给朋友

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏