出行必备小功能,日常检测风险等级变化,更好制定出行规划和核酸检测!
测试截图:
数据来源:https://news.qq.com/zt2020/page/feiyan.htm#/
可以自定义多个需要查询的省份,如果有疫情数据是会有详情,如果该省份无任何情况则不会有信息!
源代码:
import requests
import json
def alldata():
url = 'https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=statisGradeCityDetail'
headers = {'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36'}
r = requests.get(url, headers)
res = json.loads(r.text)
return res
def chaxun(path):
alltxt = ""
data = alldata()['data']['statisGradeCityDetail']
for i in data:
if path in i['province']:
txt = '截至时间:'+str(i['date'])+'\n'+str(path)+str(i['city'])+'|风险等级:'+str(i['grade'])+'\n'+'------------'+'\n'
#print(txt)
alltxt = alltxt+txt
alltxt.replace('\n', '').replace('\r', '')
return alltxt
def province():
allsms = ''
list = ["四川","广东","安徽"]#按格式进行替换自己需要的省
for path in list:
sms = chaxun(path)
allsms = allsms+sms
allsms.replace('\n', '').replace('\r', '')
try:
headers={
"User-Agent":"Mozilla/5.0 (Linux; Android 9; SM-A102U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36",
"Content-Type": "application/json"
}
url="http://www.pushplus.plus/send"
data={
"token":"替换自己的token",
"title":"疫情等级推送",
"content":str(allsms),
"template":"html"
}
res = requests.post(url=url,json=data,headers=headers)
print(res.status_code)
#print(res.text)
out = "发送通知成功"
#print(out)
except:
out = "发送通知失败"
#print(out)
return out
outall = province()
print(outall)