File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 11"""app.data"""
22from ..services .location .csbs import CSBSLocationService
33from ..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
910def data_source (source ):
Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ class Sources(str, Enum):
88
99 jhu = "jhu"
1010 csbs = "csbs"
11+ nyt = "nyt"
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments