Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Currently 2 different data-sources are available to retrieve the data:

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

* **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.

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

## API Reference
Expand Down Expand Up @@ -71,7 +73,8 @@ __Sample response__
{
"sources": [
"jhu",
"csbs"
"csbs",
"nyt"
]
}
```
Expand All @@ -87,7 +90,7 @@ GET /v2/latest
__Query String Parameters__
| __Query string parameter__ | __Description__ | __Type__ |
| -------------------------- | -------------------------------------------------------------------------------- | -------- |
| source | The data-source where data will be retrieved from *(jhu/csbs)*. Default is *jhu* | String |
| source | The data-source where data will be retrieved from *(jhu/csbs/nyt)*. Default is *jhu* | String |

__Sample response__
```json
Expand Down Expand Up @@ -117,7 +120,7 @@ __Path Parameters__
__Query String Parameters__
| __Query string parameter__ | __Description__ | __Type__ |
| -------------------------- | -------------------------------------------------------------------------------- | -------- |
| source | The data-source where data will be retrieved from *(jhu/csbs)*. Default is *jhu* | String |
| source | The data-source where data will be retrieved from *(jhu/csbs/nyt)*. Default is *jhu* | String |

#### Example Request
```http
Expand Down Expand Up @@ -160,7 +163,7 @@ GET /v2/locations
__Query String Parameters__
| __Query string parameter__ | __Description__ | __Type__ |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | -------- |
| source | The data-source where data will be retrieved from.<br>__Value__ can be: *jhu/csbs*. __Default__ is *jhu* | String |
| source | The data-source where data will be retrieved from.<br>__Value__ can be: *jhu/csbs/nyt*. __Default__ is *jhu* | String |
| 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 |
| timelines | To set the visibility of timelines (*daily tracking*).<br>__Value__ can be: *0/1*. __Default__ is *0* (timelines are not visible) | Integer |

Expand Down
4 changes: 3 additions & 1 deletion app/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""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()}
# DATA_SOURCES = {"jhu": JhuLocationService(), "csbs": CSBSLocationService()}


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"
54 changes: 54 additions & 0 deletions app/services/location/nyt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""app.services.location.nyt.py"""
import csv
from datetime import datetime

from asyncache import cached
from cachetools import TTLCache

from ...utils import httputils
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():
"""
Retrieves the locations from the categories. The locations are cached for 1 hour.

:returns: The locations.
:rtype: List[Location]
"""
pass
'''
async with httputils.CLIENT_SESSION.get(BASE_URL) as response:
text = await response.text()

data = list(csv.DictReader(text.splitlines()))
'''