Skip to content

Commit

Permalink
Merge pull request #19 from kupad95/kupad95-patch-1
Browse files Browse the repository at this point in the history
add India state-level data
  • Loading branch information
nnoll authored Mar 22, 2020
2 parents bfec244 + 4730b0d commit 9a48498
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
52 changes: 52 additions & 0 deletions parsers/india.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os, sys
import csv
import json
import requests
import numpy as np

from collections import defaultdict
from datetime import datetime
from .utils import write_tsv

# ------------------------------------------------------------------------
# Globals

URL = "https://api.rootnet.in/covid19-in/stats/daily"
LOC = "case-counts/Asia/Southern Asia/India"
cols = ['time', 'cases', 'deaths', 'hospitalized', 'ICU', 'recovered']

# ------------------------------------------------------------------------
# Functions

def sorted_date(s):
return sorted(s, key=lambda d: datetime.strptime(d[cols.index('time')], "%Y-%m-%d"))

# ------------------------------------------------------------------------
# Main point of entry

def parse():
r = requests.get(URL)
if not r.ok:
print(f"Failed to fetch {URL}", file=sys.stderr)
exit(1)
r.close()

dbindia = json.loads(r.text)['data']
r.close()

# Convert to ready made TSVs
states = defaultdict(list)
for row in dbindia:
dates = row["day"]
for i in row['regional']:
confirmedCases = i["confirmedCasesIndian"] + i["confirmedCasesForeign"]
deaths = i["deaths"]
locations = i['loc']
elt = [ dates, confirmedCases, deaths, None, None, None ]
states[locations].append(elt)

for cntry, data in states.items():
states[cntry] = sorted_date(states[cntry])

for state, data in states.items():
write_tsv(f"{LOC}/{state}.tsv", cols, data, "india")
36 changes: 36 additions & 0 deletions populationData.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,39 @@ USA-Florida 21992985 United States of America 57182 1906 300 10
USA-Texas 29472295 United States of America 67786 2260 200 10
USA-California 39937489 United States of America 71887 2396 1000 10
India 1380004385 India 1376013 70000 5 40
India-Andhra Pradesh 52883163 India 23138 2278 0 2
IND-Arunachal Pradesh 1528296 India 2404 236 0 0.1
IND-Assam 34586234 India 17142 1688 0 1
IND-Bihar 119461013 India 12019 1183 0 1
IND-Chhattisgarh 28566990 India 9412 926 0 0.1
IND-Goa 1542750 India 3013 296 0 0.1
IND-Gujarat 63907200 India 32280 3179 0 3
IND-Haryana 27388008 India 11240 1106 0 1
IND-Himachal Pradesh 7316708 India 12399 1221 0 1
IND-Jammu & Kashmir 13635010 India 11651 1147 0 1
IND-Jharkhand 37329128 India 10784 1062 0 1
IND-Karnataka 66165886 India 70165 6910 0 6
IND-Kerala 35330888 India 38004 3742 3 3
IND-Madhya Pradesh 82342793 India 28839 2840 0 2
IND-Maharashtra 120837347 India 51446 5066 0 5
IND-Manipur 3008546 India 1427 140 0 0.1
IND-Meghalaya 3276323 India 4457 438 0 0.1
IND-Mizoram 1205974 India 1997 196 0 0.1
IND-Nagaland 2189297 India 1880 185 0 0.1
IND-Odisha 45429399 India 18519 1823 0 1
IND-Punjab 29611935 India 17933 1766 0 1
IND-Rajasthan 78230816 India 31848 3136 0 3
IND-Sikkim 671720 India 1560 153 0 0.1
IND-Tamil Nadu 76481545 India 77532 7635 0 7
IND-Telangana 38472769 India 20983 2066 1 2
IND-Tripura 4057847 India 4417 435 0 0.1
IND-Uttar Pradesh 228959599 India 76260 7510 0 7
IND-Uttarakhand 11090425 India 8512 838 0 0.1
IND-West Bengal 97694960 India 78566 7737 0 7
IND-Andaman & Nicobar Islands 419978 India 1075 105 0 0.1
IND-Chandigarh 1126705 India 778 76 0 0.1
IND-Dadra & Nagar Haveli 378979 India 589 58 0 0.1
IND-Daman & Diu 220084 India 240 23 0 0.1
IND-Delhi 18345784 India 24383 2401 1 2
IND-Lakshadweep 71218 India 300 29 0 0.1
IND-Puducherry 1375592 India 3569 351 0 0.1
5 changes: 5 additions & 0 deletions sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@
"primarySource": "https://coronadatascraper.com/timeseries-byLocation.json",
"dataProvenance": "Coronadatascraper.com",
"license": "Scraped from many sources, no clear license"
},
"india": {
"primarySource": "https://api.rootnet.in/covid19-in/stats/daily",
"dataProvenance": "https://github.com/amodm/api-covid19-in",
"license": "Scraped from Ministry of Health and Family Welfare plus other sources, no clear license"
}
}

0 comments on commit 9a48498

Please sign in to comment.