-
Notifications
You must be signed in to change notification settings - Fork 36
/
2019-nCov.py
165 lines (136 loc) · 5.97 KB
/
2019-nCov.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import requests
import re
from random import randint
from bs4 import BeautifulSoup
from time import sleep
import json
from prettytable import ALL
from prettytable import PrettyTable
# 省份 城市, 确诊, 死亡, 治愈, 疑似
# China = [{"province":"河南", cities:[[信阳", 10, 0, 10, 10], [], []]}, {}, {}, {}]
China = []
headers = {
'user-agent':'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1',
'accept':'*/*',
'Connection':'keep-alive',
'Referer':'https://lab.isaaclin.cn/nCoV/',
'Accept-Language':'zh-CN,zh;q=0.8',
'Upgrade-Insecure-Requests':'1'
}
def query(province):
table = PrettyTable(['地区', '确诊', '死亡', '治愈'])
if province == "新疆":
province += "维吾尔自治区"
elif province == "西藏" or province == "内蒙古":
province += "自治区"
elif province == "广西":
province += "壮族自治区"
elif province == "宁夏":
province += "回族自治区"
elif province != "香港" and province != "澳门" and province != "台湾":
province += "省"
url = "https://lab.isaaclin.cn/nCoV/api/area?latest=1&province=" + province
json_str = json.loads(requests.get(url, headers=headers).text)
if json_str['success']:
if len(json_str['results'][0]['cities']):
for data in json_str['results'][0]['cities']:
confirmed = data['confirmedCount'] if data['confirmedCount'] != 0 else '-'
dead = data['deadCount'] if data['deadCount'] != 0 else '-'
cured = data['curedCount'] if data['curedCount'] != 0 else '-'
table.add_row([data['cityName'], confirmed, dead, cured])
print(table)
return
else:
print("暂无相关信息")
else:
print("暂无相关信息")
return
def main():
try:
url = "https://lab.isaaclin.cn/nCoV/api/overall"
table = PrettyTable(['地区', '确诊', '死亡', '治愈'])
table.hrules = ALL
while True:
r = requests.get(url, headers=headers)
r.encoding = r.apparent_encoding
json_str = json.loads(r.text)
if json_str['success']:
break
else:
sleep(1)
print()
print("==================================全国数据==================================")
print()
print(" 确诊 " + str(json_str['results'][0]['confirmedCount']) + " 例"
+ " " + "疑似 " + str(json_str['results'][0]['suspectedCount']) + " 例"
+ " " + "死亡 " + str(json_str['results'][0]['deadCount']) + " 例"
+ " " + "治愈 " + str(json_str['results'][0]['curedCount']) + " 例\n")
print("==================================相关情况==================================")
print()
print(json_str['results'][0]['remark3'])
print(json_str['results'][0]['note1'])
print(json_str['results'][0]['note2'])
print(json_str['results'][0]['remark1'])
print(json_str['results'][0]['note3'])
print(json_str['results'][0]['remark2'] + "\n")
print("==================================国内情况==================================")
print()
url = "http://www.dzyong.top:3005/yiqing/province"
r = requests.get(url, headers=headers)
r.encoding = r.apparent_encoding
json_info = json.loads(r.text)
for data in json_info['data']:
confirmed = data['confirmedNum'] if data['confirmedNum'] != 0 else '-'
dead = data['deathsNum'] if data['deathsNum'] != 0 else '-'
cured = data['curesNum'] if data['curesNum'] != 0 else '-'
table.add_row([data['provinceName'], confirmed, dead, cured])
print(table)
sleep(1)
print()
print("==================================国外情况==================================")
print()
url = "https://lab.isaaclin.cn/nCoV/api/area"
table = PrettyTable(['地区', '确诊', '死亡', '治愈'])
table.hrules = ALL
while True:
r = requests.get(url, headers=headers)
r.encoding = r.apparent_encoding
json_str = json.loads(r.text)
if json_str['success']:
break
else:
sleep(1)
sleep(1)
for data in json_str['results']:
if data['countryName'] != '中国':
confirmed = data['confirmedCount'] if data['confirmedCount'] != 0 else '-'
dead = data['deadCount'] if data['deadCount'] != 0 else '-'
cured = data['curedCount'] if data['curedCount'] != 0 else '-'
table.add_row([data['provinceName'], confirmed , dead, cured])
print(table)
print()
print("==================================最新消息==================================")
print()
url = "https://lab.isaaclin.cn/nCoV/api/news"
while True:
json_info = json.loads(requests.get(url, headers=headers).text)
if json_info['success']:
break
else:
sleep(1)
idx = 0
for data in json_info['results']:
if idx >= 5:
break
print(str(data['title']).strip())
idx = idx + 1
print()
key = input("请输入您想查询详细信息的省份,例如 湖北\n")
print()
query(key)
print("\n欢迎提出各种意见")
except:
print("连接失败,请在Github中提出Issue,或者联系QQ16036505")
if __name__ == '__main__':
main()
sleep(30)