1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| import requests,json from tkinter import * import base64,os
def get_data(): api = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5' data = requests.get(api) data.encoding = 'utf-8' data = json.loads(data.text) data = json.loads(data['data'])["areaTree"] return data
def analytical_data(地区,data=get_data()): data2 = 0 temp = 0 for i in data: if i['name'] == 地区: if temp == 1: break data2 = i temp = 1 break if temp==0: for i in data[0]["children"]: if i['name'] == 地区: data2 = i temp = 1 break if temp==0: for i in data[0]["children"]: for j in i["children"]: if j['name'] == 地区: temp = 1 data2 = j break if temp == 1: break return data2
def main(): data = analytical_data(inputbox.get()) t.delete('1.0', 'end') try: var = '关于{}的最新疫情信息如下:\n确诊人数:{}\n疑似人数:{}\n治愈人数:{}\n死亡人数:{}\n新增确诊:{}\n由于API问题疑似可能不准\n武汉加油!中国加油!' var = var.format(inputbox.get(),str(data["total"]["confirm"])+'人',str(data["total"]["suspect"]) + '人',str(data["total"]["heal"])+'人',str(data["total"]["dead"])+'人',str(data["today"]["confirm"])+'人') except: var = '未找到地区:'+inputbox.get() t.insert('end',var) window = Tk() window.title('新冠肺炎疫情查询') window.geometry('375x330') window.resizable(0,0) diqu_text = Label(window,text='地区',width=3,height=1,font=('微软雅黑',12)) diqu_text.place(x=50,y=30, anchor='nw') inputbox = Entry(window,width=10,font=('微软雅黑',16)) inputbox.place(x=110,y=30, anchor='nw') t = Text(window,height=11,width=35,font=('微软雅黑',10)) t.place(x=40,y=80) b = Button(window,text='查询',width=6,height=1,font=('微软雅黑',10),command=main) b.place(x=250,y=29, anchor='nw')
window.mainloop()
|