Skip to content

Commit 9ffe9e6

Browse files
committed
Started nyt.py file in services.location module
1 parent e8cd213 commit 9ffe9e6

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

app/data/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
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()}
78

89

910
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 . import LocationService
9+
10+
11+
class NYTLocationService(LocationService):
12+
"""
13+
Service for retrieving locations from New York Times (https://github.com/nytimes/covid-19-data).
14+
"""
15+
16+
async def get_all(self):
17+
# Get the locations.
18+
locations = await get_locations()
19+
return locations
20+
21+
async def get(self, loc_id): # pylint: disable=arguments-differ
22+
# Get location at the index equal to provided id.
23+
locations = await self.get_all()
24+
return locations[loc_id]
25+
26+
27+
# ---------------------------------------------------------------
28+
29+
30+
# Base URL for fetching category.
31+
BASE_URL = "https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv"
32+
33+
34+
@cached(cache=TTLCache(maxsize=1024, ttl=3600)) # TODO
35+
async def get_category(category):
36+
pass
37+
38+
39+
@cached(cache=TTLCache(maxsize=1024, ttl=3600))
40+
async def get_locations():
41+
pass

0 commit comments

Comments
 (0)