Skip to content

Commit 0a82678

Browse files
author
ExpDev07
committed
still support old recoveries
1 parent d3f0ab8 commit 0a82678

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

app/routes/v1/all.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from flask import jsonify
2-
from .recovered import dummy
32
from ...routes import api_v1 as api
43
from ...services.location.jhu import get_category
54

@@ -8,17 +7,18 @@ def all():
87
# Get all the categories.
98
confirmed = get_category('confirmed')
109
deaths = get_category('deaths')
10+
recovered = get_category('recovered')
1111

1212
return jsonify({
1313
# Data.
1414
'confirmed': confirmed,
1515
'deaths': deaths,
16-
'recovered': dummy,
16+
'recovered': recovered,
1717

1818
# Latest.
1919
'latest': {
2020
'confirmed': confirmed['latest'],
2121
'deaths': deaths['latest'],
22-
'recovered': 0,
22+
'recovered': recovered['latest'],
2323
}
2424
})

app/routes/v1/recovered.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
from flask import jsonify
22
from ...routes import api_v1 as api
3-
4-
# Dummy response.
5-
dummy = {
6-
'source' : 'https://github.com/ExpDev07/coronavirus-tracker-api',
7-
'last_updated': '2020-03-24T03:57:10.057450Z',
8-
'latest' : 0,
9-
'locations' : [],
10-
}
3+
from ...services.location.jhu import get_category
114

125
@api.route('/recovered')
136
def recovered():
14-
# Dummy data.
15-
return jsonify(dummy)
7+
return jsonify(get_category('recovered'))

app/services/location/jhu.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get(self, id):
2727
"""
2828
Base URL for fetching category.
2929
"""
30-
base_url = 'https://raw.githubusercontent.com/CSSEGISandData/2019-nCoV/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_%s_global.csv';
30+
base_url = 'https://raw.githubusercontent.com/CSSEGISandData/2019-nCoV/master/csse_covid_19_data/csse_covid_19_time_series/';
3131

3232
@cached(cache=TTLCache(maxsize=1024, ttl=3600))
3333
def get_category(category):
@@ -41,8 +41,18 @@ def get_category(category):
4141
# Adhere to category naming standard.
4242
category = category.lower();
4343

44+
# URL to request data from.
45+
url = base_url + 'time_series_covid19_%s_global.csv' % category
46+
47+
# Different URL is needed for recoveries.
48+
# Read about deprecation here: https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_time_series.
49+
if category == 'recovered':
50+
url = base_url + 'time_series_19-covid-Recovered.csv'
51+
52+
print (url)
53+
4454
# Request the data
45-
request = requests.get(base_url % category)
55+
request = requests.get(url)
4656
text = request.text
4757

4858
# Parse the CSV.
@@ -106,6 +116,7 @@ def get_locations():
106116
# Get all of the data categories locations.
107117
confirmed = get_category('confirmed')['locations']
108118
deaths = get_category('deaths')['locations']
119+
recovered = get_category('recovered')['locations']
109120

110121
# Final locations to return.
111122
locations = []
@@ -116,7 +127,7 @@ def get_locations():
116127
timelines = {
117128
'confirmed' : confirmed[index]['history'],
118129
'deaths' : deaths[index]['history'],
119-
'recovered' : {},
130+
'recovered' : recovered[index]['history'],
120131
}
121132

122133
# Grab coordinates.
@@ -140,7 +151,7 @@ def get_locations():
140151
{
141152
'confirmed': Timeline({ datetime.strptime(date, '%m/%d/%y').isoformat() + 'Z': amount for date, amount in timelines['confirmed'].items() }),
142153
'deaths' : Timeline({ datetime.strptime(date, '%m/%d/%y').isoformat() + 'Z': amount for date, amount in timelines['deaths'].items() }),
143-
'recovered': Timeline({})
154+
'recovered': Timeline({ datetime.strptime(date, '%m/%d/%y').isoformat() + 'Z': amount for date, amount in timelines['recovered'].items() })
144155
}
145156
))
146157

0 commit comments

Comments
 (0)