Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Started nyt.py file in services.location module
  • Loading branch information
ibhuiyan17 committed Apr 7, 2020
commit 9ffe9e6540eb8f1235b430401654a9e27a34b88c
3 changes: 2 additions & 1 deletion app/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""app.data"""
from ..services.location.csbs import CSBSLocationService
from ..services.location.jhu import JhuLocationService
from ..services.location.nyt import NYTLocationService

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


def data_source(source):
Expand Down
1 change: 1 addition & 0 deletions app/enums/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ class Sources(str, Enum):

jhu = "jhu"
csbs = "csbs"
nyt = "nyt"
41 changes: 41 additions & 0 deletions app/services/location/nyt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""app.services.location.nyt.py"""
import csv
from datetime import datetime

from asyncache import cached
from cachetools import TTLCache

from . import LocationService


class NYTLocationService(LocationService):
"""
Service for retrieving locations from New York Times (https://github.com/nytimes/covid-19-data).
"""

async def get_all(self):
# Get the locations.
locations = await get_locations()
return locations

async def get(self, loc_id): # pylint: disable=arguments-differ
# Get location at the index equal to provided id.
locations = await self.get_all()
return locations[loc_id]


# ---------------------------------------------------------------


# Base URL for fetching category.
BASE_URL = "https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv"


@cached(cache=TTLCache(maxsize=1024, ttl=3600)) # TODO
async def get_category(category):
pass


@cached(cache=TTLCache(maxsize=1024, ttl=3600))
async def get_locations():
pass