Skip to content

Commit d3f0ab8

Browse files
author
ExpDev07
committed
updated
1 parent 1faac27 commit d3f0ab8

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

app/routes/v1/all.py

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

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

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

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

app/routes/v1/recovered.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
from flask import jsonify
22
from ...routes import api_v1 as api
3-
from ...services.location.jhu import get_category
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+
}
411

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

app/services/location/jhu.py

Lines changed: 4 additions & 5 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_19-covid-%s.csv';
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';
3131

3232
@cached(cache=TTLCache(maxsize=1024, ttl=3600))
3333
def get_category(category):
@@ -39,7 +39,7 @@ def get_category(category):
3939
"""
4040

4141
# Adhere to category naming standard.
42-
category = category.lower().capitalize();
42+
category = category.lower();
4343

4444
# Request the data
4545
request = requests.get(base_url % category)
@@ -106,7 +106,6 @@ def get_locations():
106106
# Get all of the data categories locations.
107107
confirmed = get_category('confirmed')['locations']
108108
deaths = get_category('deaths')['locations']
109-
recovered = get_category('recovered')['locations']
110109

111110
# Final locations to return.
112111
locations = []
@@ -117,7 +116,7 @@ def get_locations():
117116
timelines = {
118117
'confirmed' : confirmed[index]['history'],
119118
'deaths' : deaths[index]['history'],
120-
'recovered' : recovered[index]['history'],
119+
'recovered' : {},
121120
}
122121

123122
# Grab coordinates.
@@ -141,7 +140,7 @@ def get_locations():
141140
{
142141
'confirmed': Timeline({ datetime.strptime(date, '%m/%d/%y').isoformat() + 'Z': amount for date, amount in timelines['confirmed'].items() }),
143142
'deaths' : Timeline({ datetime.strptime(date, '%m/%d/%y').isoformat() + 'Z': amount for date, amount in timelines['deaths'].items() }),
144-
'recovered': Timeline({ datetime.strptime(date, '%m/%d/%y').isoformat() + 'Z': amount for date, amount in timelines['recovered'].items() })
143+
'recovered': Timeline({})
145144
}
146145
))
147146

app/timeline.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ def latest(self):
2121
"""
2222
Gets the latest available history value.
2323
"""
24-
return list(self.timeline.values())[-1] or 0
24+
# Get values in a list.
25+
values = list(self.timeline.values())
26+
27+
# Last item is the latest.
28+
if len(values):
29+
return values[-1] or 0
30+
31+
# Fallback value of 0.
32+
return 0
2533

2634
def serialize(self):
2735
"""

0 commit comments

Comments
 (0)