Skip to content

Commit cbca556

Browse files
Kilo59ExpDev07ExpDev07
authored
Upstream updates (#9)
* fixed wrong date format and timelines appearing null * fix csbs changing date format (for the second time) * updated * still support old recoveries * fix tests * fix tests (2) * oops * now * now? * tests fixed * finally fixed tests * works * add funding option :) * hotfix * fix test * Update README.md * Update README.md Co-authored-by: ExpDev <[email protected]> Co-authored-by: ExpDev07 <[email protected]>
1 parent 9d22cd5 commit cbca556

File tree

14 files changed

+106
-293
lines changed

14 files changed

+106
-293
lines changed

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
#github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
#patreon: # Replace with a single Patreon username
5+
#open_collective: # Replace with a single Open Collective username
6+
ko_fi: ExpDev
7+
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
#liberapay: # Replace with a single Liberapay username
10+
#issuehunt: # Replace with a single IssueHunt username
11+
#otechie: # Replace with a single Otechie username
12+
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
## Coronavirus Tracker API
1+
<h1 align="center">
2+
Coronavirus Tracker API
3+
</h1>
4+
25
Provides up-to-date data about Coronavirus outbreak. Includes numbers about confirmed cases, deaths and recovered.
36
Support multiple data-sources.
47

@@ -18,6 +21,10 @@ Support multiple data-sources.
1821
![Covid-19 Recovered](https://covid19-badges.herokuapp.com/recovered/latest)
1922
![Covid-19 Deaths](https://covid19-badges.herokuapp.com/deaths/latest)
2023

24+
## Recovered cases showing 0
25+
26+
**JHU (our main data provider) [no longer provides data for amount of recoveries](https://github.com/ExpDev07/coronavirus-tracker-api/issues/155), and as a result, the API will be showing 0 for this statistic. Apolegies for any inconvenience. Hopefully we'll be able to find an alternative data-source that offers this.**
27+
2128
## Available data-sources:
2229

2330
Currently 2 different data-sources are available to retrieve the data:
@@ -28,7 +35,6 @@ Currently 2 different data-sources are available to retrieve the data:
2835

2936
__jhu__ data-source will be used as a default source if you don't specify a *source parameter* in your request.
3037

31-
3238
## API Reference
3339

3440
All endpoints are located at ``coronavirus-tracker-api.herokuapp.com/v2/`` and are accessible via https. For instance: you can get data per location by using this URL:
@@ -40,7 +46,6 @@ You can open the URL in your browser to further inspect the response. Or you can
4046
curl https://coronavirus-tracker-api.herokuapp.com/v2/locations | json_pp
4147
```
4248

43-
4449
## API Endpoints
4550

4651
### Sources Endpoint

app/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_latest(request: fastapi.Request, source: Sources = "jhu"):
8989

9090

9191
@V2.get(
92-
"/locations", response_model=models.AllLocations, response_model_exclude_unset=True
92+
"/locations", response_model=models.Locations, response_model_exclude_unset=True
9393
)
9494
def get_all_locations(
9595
request: fastapi.Request,
@@ -131,8 +131,9 @@ async def sources():
131131
"""
132132
return {"sources": list(data_sources.keys())}
133133

134-
134+
# Include routers.
135135
APP.include_router(V2, prefix="/v2-beta", tags=["v2"])
136+
136137
# mount the existing Flask app
137138
# v1 @ /
138139
# v2 @ /v2

app/models.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,45 @@
33
~~~~~~~~~~~~~
44
Reponse data models.
55
"""
6-
import datetime as dt
6+
from pydantic import BaseModel
77
from typing import Dict, List
88

9-
import pydantic
10-
11-
12-
class Totals(pydantic.BaseModel):
9+
class Totals(BaseModel):
1310
confirmed: int
1411
deaths: int
1512
recovered: int
1613

1714

18-
class Latest(pydantic.BaseModel):
15+
class Latest(BaseModel):
1916
latest: Totals
2017

2118

22-
class TimelineStats(pydantic.BaseModel):
19+
class TimelineStats(BaseModel):
2320
latest: int
24-
timeline: Dict[str, int]
21+
timeline: Dict[str, int] = {}
2522

2623

27-
class TimelinedLocation(pydantic.BaseModel):
24+
class TimelinedLocation(BaseModel):
2825
confirmed: TimelineStats
2926
deaths: TimelineStats
3027
recovered: TimelineStats
3128

3229

33-
class Country(pydantic.BaseModel):
34-
coordinates: Dict
30+
class Country(BaseModel):
31+
id: int
3532
country: str
3633
country_code: str
37-
id: int
38-
last_updated: dt.datetime
39-
latest: Totals
4034
province: str = ""
41-
timelines: TimelinedLocation = None # FIXME
35+
last_updated: str # TODO use datetime.datetime type.
36+
coordinates: Dict
37+
latest: Totals
38+
timelines: TimelinedLocation = {}
4239

4340

44-
class AllLocations(pydantic.BaseModel):
41+
class Locations(BaseModel):
4542
latest: Totals
46-
locations: List[Country]
43+
locations: List[Country] = []
4744

4845

49-
class Location(pydantic.BaseModel):
46+
class Location(BaseModel):
5047
location: Country

app/services/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
from .location.jhu import JhuLocationService
2-
from .location.csbs import CSBSLocationService
3-
4-
# Instances of the services.
5-
jhu = JhuLocationService()
6-
csbs = CSBSLocationService()

app/services/location/csbs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def get_locations():
6767
),
6868

6969
# Last update (parse as ISO).
70-
datetime.strptime(last_update, '%Y/%m/%d %H:%M').isoformat() + 'Z',
70+
datetime.strptime(last_update, '%Y-%m-%d %H:%M').isoformat() + 'Z',
7171

7272
# Statistics.
7373
int(item['Confirmed'] or 0),

app/services/location/jhu.py

Lines changed: 16 additions & 6 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/';
3131

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

4141
# Adhere to category naming standard.
42-
category = category.lower().capitalize();
42+
category = category.lower();
43+
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)
4353

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,7 +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']
109-
recovered = get_category('recovered')['locations']
119+
# recovered = get_category('recovered')['locations']
110120

111121
# Final locations to return.
112122
locations = []
@@ -117,7 +127,7 @@ def get_locations():
117127
timelines = {
118128
'confirmed' : confirmed[index]['history'],
119129
'deaths' : deaths[index]['history'],
120-
'recovered' : recovered[index]['history'],
130+
# 'recovered' : recovered[index]['history'],
121131
}
122132

123133
# Grab coordinates.
@@ -141,7 +151,7 @@ def get_locations():
141151
{
142152
'confirmed': Timeline({ datetime.strptime(date, '%m/%d/%y').isoformat() + 'Z': amount for date, amount in timelines['confirmed'].items() }),
143153
'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() })
154+
'recovered': Timeline({})
145155
}
146156
))
147157

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
"""

coronavirus-tracker-api-swagger.yaml

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)