python script which creates a map in html showing realtime covid stat… (#138)

* python script which creates a map in html showing realtime covid status in india

* remove extra space; fix allignment

Co-authored-by: Ayush Bhardwaj <classicayush@gmail.com>
This commit is contained in:
tushar5526 2020-05-08 13:34:12 +05:30 committed by GitHub
parent 0d812076d4
commit eff5756354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1222 additions and 0 deletions

View File

@ -144,6 +144,7 @@ So far, the following projects have been integrated to this repo:
|[File Organizer](File-Organizer)|[Ayush Bhardwaj](https://github.com/hastagAB)|
|[send_whatsapp_message](send_whatsapp_message)|[Mukesh Prasad](https://github.com/mukeshprasad)|
|[YTS Torrents](yts_torrents)|[Mayank Nader](https://github.com/makkoncept)|
|[COVID visualiser (real-time) ](covdi_visualiser)|[Tushar Gupta](https://github.com/tushar5526)|
## How to use :

View File

@ -0,0 +1,13 @@
--> Clone the project
--> run pip install -r requirements.txt
-- > python3 main.py
-- >It will launch a firefox tab showing the map
This project visualise the current COVID position of India on a map using Folium
(will extend it to more countries later)

View File

@ -0,0 +1 @@
[{"city": "Mumbai", "state": "Maharashtra", "statecode": "MH", "lat": "18.987807", "lng": "72.836447"}, {"city": "New Delhi", "state": "Delhi", "statecode": "DL", "lat": "28.6", "lng": "77.2"}, {"city": "Gandhinagar", "state": "Gujarat", "statecode": "GJ", "lat": "23.216667", "lng": "72.683333"}, {"city": "Jaipur", "state": "Rajasthan", "statecode": "RJ", "lat": "26.913312", "lng": "75.787872"}, {"city": "Chennai", "state": "Tamil Nadu", "statecode": "TN", "lat": "13.084622", "lng": "80.248357"}, {"city": "Bhopal", "state": "Madhya Pradesh", "statecode": "MP", "lat": "23.254688", "lng": "77.402892"}, {"city": "Lucknow", "state": "Uttar Pradesh", "statecode": "UP", "lat": "26.839281", "lng": "80.923133"}, {"city": "Amaravati", "state": "Andhra Pradesh", "statecode": "AP", "lat": "17.384052", "lng": "78.456355"}, {"city": "Bengaluru", "state": "Karnataka", "statecode": "KA", "lat": "12.977063", "lng": "77.587106"}, {"city": "Thiruvananthapuram", "state": "Kerala", "statecode": "KL", "lat": "8.485498", "lng": "76.949238"}, {"city": "Jammu", "state": "Jammu and Kashmir", "statecode": "JK", "lat": "32.735686", "lng": "74.869112"}, {"city": "Kolkata", "state": "West Bengal", "statecode": "WB", "lat": "22.562627", "lng": "88.363044"}, {"city": "Chandigarh", "state": "Haryana", "statecode": "HR", "lat": "30.736292", "lng": "76.788398"}, {"city": "Chandigarh", "state": "Punjab", "statecode": "PB", "lat": "30.736292", "lng": "76.788398"}, {"city": "Patna", "state": "Bihar", "statecode": "BR", "lat": "25.615379", "lng": "85.101027"}, {"city": "Bhubaneswar", "state": "Odisha", "statecode": "OR", "lat": "20.272411", "lng": "85.833853"}, {"city": "Ranchi", "state": "Jharkhand", "statecode": "JH", "lat": "23.347768", "lng": "85.338564"}, {"city": "Shimla", "state": "Himachal Pradesh", "statecode": "HP", "lat": "31.104423", "lng": "77.166623"}, {"city": "Dispur", "state": "Assam", "statecode": "AS", "lat": "26.135638", "lng": "91.800688"}, {"city": "Raipur", "state": "Chandigarh", "statecode": "CH", "lat": "21.233333", "lng": "81.633333"}, {"city": "Leh", "state": "Ladakh", "statecode": "LA", "lat": "34.1526", "lng": "77.55771"}, {"city": "Mayabunder", "state": "Andaman and Nicobar Islands", "statecode": "AN", "lat": "12.9131", "lng": "92.8977"}, {"city": "Shillong", "state": "Meghalaya", "statecode": "ML", "lat": "25.573987", "lng": "91.896807"}, {"city": "Panaji", "state": "Goa", "statecode": "GA", "lat": "15.498289", "lng": "73.824541"}, {"city": "Puducherry", "state": "Puducherry", "statecode": "PY", "lat": "11.933812", "lng": "79.829792"}, {"city": "Imphal", "state": "Manipur", "statecode": "MN", "lat": "24.808053", "lng": "93.944203"}, {"city": "Agartala", "state": "Tripura", "statecode": "TR", "lat": "23.836049", "lng": "91.279386"}, {"city": "Aizawl", "state": "Mizoram", "statecode": "MZ", "lat": "23.736701", "lng": "92.714596"}, {"city": "Itanagar", "state": "Arunachal Pradesh", "statecode": "AR", "lat": "27.102349", "lng": "93.692047"}, {"city": "Kohima", "state": "Nagaland", "statecode": "NL", "lat": "25.674673", "lng": "94.110988"}, {"city": "Daman", "state": "Daman and Diu", "statecode": "DD", "lat": "20.414315", "lng": "72.83236"}, {"city": "Kavaratti", "state": "Lakshadweep", "statecode": "LD", "lat": "10.566667", "lng": "72.616667"}, {"city": "Gangtok", "state": "Sikkim", "statecode": "SK", "lat": "27.325739", "lng": "88.612155"}]

54
covid_visualiser/main.py Normal file
View File

@ -0,0 +1,54 @@
import os
import folium
import requests
import json
r = requests.get(url='https://api.covid19india.org/data.json')
statewise_covid_data = json.loads(r.content)['statewise']
with open('capital_data.json', 'r') as f:
json_text = f.read()
city_data = json.loads(json_text)
for i in range(1,len(statewise_covid_data)):
for j in range(len(city_data)):
if statewise_covid_data[i]['statecode'] == city_data[j]['statecode']:
city_data[j]['confirmed'] = statewise_covid_data[i]['confirmed']
city_data[j]['deaths'] = statewise_covid_data[i]['deaths']
break
mp = folium.Map(location = [city_data[1]['lat'],city_data[1]['lng']],zoom_start= 5)
for i in range(len(city_data)):
if float(city_data[i]['deaths']) > 50:
folium.Marker(location = [city_data[i]['lat'],city_data[i]['lng']],
popup = city_data[i]['state'],
icon=folium.Icon(color='darkred',icon_color='white',icon='remove-sign',),
tooltip = 'deaths: ' + city_data[i]['deaths'] + ' confirmed: ' + city_data[i]['confirmed']
).add_to(mp)
elif float(city_data[i]['deaths']) > 20:
folium.Marker(location = [city_data[i]['lat'],city_data[i]['lng']],
popup = city_data[i]['state'],
icon=folium.Icon(color='red',icon_color='white',icon='ban-circle',),
tooltip = 'deaths: ' + city_data[i]['deaths'] + ' confirmed: ' + city_data[i]['confirmed']
).add_to(mp)
elif float(city_data[i]['deaths']) > 0:
folium.Marker(location = [city_data[i]['lat'],city_data[i]['lng']],
popup = city_data[i]['state'],
icon=folium.Icon(color='orange',icon_color='white',icon='warning-sign',),
tooltip = 'deaths: ' + city_data[i]['deaths'] + ' confirmed: ' + city_data[i]['confirmed']
).add_to(mp)
elif float(city_data[i]['deaths']) == 0:
folium.Marker(location = [city_data[i]['lat'],city_data[i]['lng']],
popup = city_data[i]['state'],
icon=folium.Icon(color='green',icon_color='white',icon='ok-circle',),
tooltip = 'deaths: ' + city_data[i]['deaths'] + ' confirmed: ' + city_data[i]['confirmed']
).add_to(mp)
mp.save('map.html')
os.system('firefox map.html')

1152
covid_visualiser/map.html Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
folium==0.10.1