-
Notifications
You must be signed in to change notification settings - Fork 50
/
communities-ahusmart.py
31 lines (29 loc) · 1.19 KB
/
communities-ahusmart.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
import shutil
import urllib.request
import json
import datetime
ts = str(datetime.datetime.now().timestamp()).split(".")[0]
urllink = "https://lab.ahusmart.com/nCoV/api/detail"
id = 0
with urllib.request.urlopen(urllink) as url:
content = url.read()
cases = json.loads(content.decode())
with open("assets/communities-" + ts + ".json", "w+", encoding="utf-8") as fp:
fp.write(str(cases['results']))
with open("assets/communities-" + ts + ".csv", "w+", encoding="utf-8") as fp:
fp.write("id,name,time,lat,lng\n")
for case in cases['results']:
name = case['detail']
# province = case['province']
city = case['city']
time = case['updateTime']
source = case['infoSource']
url = case['sourceUrl']
lat = case['position'][1]
lng = case['position'][0]
fp.write("%d,%s,%d,%f,%f\n" % (id, name, time, lat, lng))
print(id, name, time, lat, lng, city, source, url)
id += 1
shutil.copyfile("assets/communities-" + ts + ".csv", "assets/communities.csv")
shutil.copyfile("assets/communities-" + ts + ".json", "assets/communities.json")
print("finished!")