Skip to content

Commit 736b90d

Browse files
2 parents a9c5f37 + 6a744a6 commit 736b90d

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Currently 2 different data-sources are available to retrieve the data:
3636

3737
* **csbs** - https://www.csbs.org/information-covid-19-coronavirus - U.S. County data that comes from the Conference of State Bank Supervisors.
3838

39+
* **nyt** - https://github.com/nytimes/covid-19-data - The New York Times is releasing a series of data files with cumulative counts of coronavirus cases in the United States, at the state and county level, over time.
40+
3941
__jhu__ data-source will be used as a default source if you don't specify a *source parameter* in your request.
4042

4143
## API Reference
@@ -71,7 +73,8 @@ __Sample response__
7173
{
7274
"sources": [
7375
"jhu",
74-
"csbs"
76+
"csbs",
77+
"nyt"
7578
]
7679
}
7780
```
@@ -87,7 +90,7 @@ GET /v2/latest
8790
__Query String Parameters__
8891
| __Query string parameter__ | __Description__ | __Type__ |
8992
| -------------------------- | -------------------------------------------------------------------------------- | -------- |
90-
| source | The data-source where data will be retrieved from *(jhu/csbs)*. Default is *jhu* | String |
93+
| source | The data-source where data will be retrieved from *(jhu/csbs/nyt)*. Default is *jhu* | String |
9194

9295
__Sample response__
9396
```json
@@ -117,7 +120,7 @@ __Path Parameters__
117120
__Query String Parameters__
118121
| __Query string parameter__ | __Description__ | __Type__ |
119122
| -------------------------- | -------------------------------------------------------------------------------- | -------- |
120-
| source | The data-source where data will be retrieved from *(jhu/csbs)*. Default is *jhu* | String |
123+
| source | The data-source where data will be retrieved from *(jhu/csbs/nyt)*. Default is *jhu* | String |
121124

122125
#### Example Request
123126
```http
@@ -160,7 +163,7 @@ GET /v2/locations
160163
__Query String Parameters__
161164
| __Query string parameter__ | __Description__ | __Type__ |
162165
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | -------- |
163-
| source | The data-source where data will be retrieved from.<br>__Value__ can be: *jhu/csbs*. __Default__ is *jhu* | String |
166+
| source | The data-source where data will be retrieved from.<br>__Value__ can be: *jhu/csbs/nyt*. __Default__ is *jhu* | String |
164167
| country_code | The ISO ([alpha-2 country_code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)) to the Country/Province for which you're calling the Endpoint | String |
165168
| timelines | To set the visibility of timelines (*daily tracking*).<br>__Value__ can be: *0/1*. __Default__ is *0* (timelines are not visible) | Integer |
166169

app/data/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""app.data"""
22
from ..services.location.csbs import CSBSLocationService
33
from ..services.location.jhu import JhuLocationService
4+
from ..services.location.nyt import NYTLocationService
45

56
# Mapping of services to data-sources.
6-
DATA_SOURCES = {"jhu": JhuLocationService(), "csbs": CSBSLocationService()}
7+
DATA_SOURCES = {"jhu": JhuLocationService(), "csbs": CSBSLocationService(), "nyt": NYTLocationService()}
8+
# DATA_SOURCES = {"jhu": JhuLocationService(), "csbs": CSBSLocationService()}
79

810

911
def data_source(source):

app/enums/sources.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ class Sources(str, Enum):
88

99
jhu = "jhu"
1010
csbs = "csbs"
11+
nyt = "nyt"

app/services/location/nyt.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""app.services.location.nyt.py"""
2+
import csv
3+
from datetime import datetime
4+
5+
from asyncache import cached
6+
from cachetools import TTLCache
7+
8+
from ...utils import httputils
9+
from . import LocationService
10+
11+
12+
class NYTLocationService(LocationService):
13+
"""
14+
Service for retrieving locations from New York Times (https://github.com/nytimes/covid-19-data).
15+
"""
16+
17+
async def get_all(self):
18+
# Get the locations.
19+
locations = await get_locations()
20+
return locations
21+
22+
async def get(self, loc_id): # pylint: disable=arguments-differ
23+
# Get location at the index equal to provided id.
24+
locations = await self.get_all()
25+
return locations[loc_id]
26+
27+
28+
# ---------------------------------------------------------------
29+
30+
31+
# Base URL for fetching category.
32+
BASE_URL = "https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv"
33+
34+
35+
@cached(cache=TTLCache(maxsize=1024, ttl=3600)) # TODO
36+
async def get_category(category):
37+
pass
38+
39+
40+
@cached(cache=TTLCache(maxsize=1024, ttl=3600))
41+
async def get_locations():
42+
"""
43+
Retrieves the locations from the categories. The locations are cached for 1 hour.
44+
45+
:returns: The locations.
46+
:rtype: List[Location]
47+
"""
48+
pass
49+
'''
50+
async with httputils.CLIENT_SESSION.get(BASE_URL) as response:
51+
text = await response.text()
52+
53+
data = list(csv.DictReader(text.splitlines()))
54+
'''

0 commit comments

Comments
 (0)