Skip to content

Commit e1857b2

Browse files
committed
formatting
1 parent e54724e commit e1857b2

File tree

21 files changed

+212
-91
lines changed

21 files changed

+212
-91
lines changed

app/data/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
from ..services.location.nyt import NYTLocationService
55

66
# Mapping of services to data-sources.
7-
DATA_SOURCES = {"jhu": JhuLocationService(), "csbs": CSBSLocationService(), "nyt": NYTLocationService()}
7+
DATA_SOURCES = {
8+
"jhu": JhuLocationService(),
9+
"csbs": CSBSLocationService(),
10+
"nyt": NYTLocationService(),
11+
}
812

913

1014
def data_source(source):

app/io.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111

1212
def save(
13-
name: str, content: Union[str, Dict, List], write_mode: str = "w", indent: int = 2, **json_dumps_kwargs
13+
name: str,
14+
content: Union[str, Dict, List],
15+
write_mode: str = "w",
16+
indent: int = 2,
17+
**json_dumps_kwargs,
1418
) -> pathlib.Path:
1519
"""Save content to a file. If content is a dictionary, use json.dumps()."""
1620
path = DATA / name
@@ -35,7 +39,12 @@ class AIO:
3539

3640
@classmethod
3741
async def save(
38-
cls, name: str, content: Union[str, Dict, List], write_mode: str = "w", indent: int = 2, **json_dumps_kwargs
42+
cls,
43+
name: str,
44+
content: Union[str, Dict, List],
45+
write_mode: str = "w",
46+
indent: int = 2,
47+
**json_dumps_kwargs,
3948
):
4049
"""Save content to a file. If content is a dictionary, use json.dumps()."""
4150
path = DATA / name

app/location/__init__.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ class Location: # pylint: disable=too-many-instance-attributes
1111
"""
1212

1313
def __init__(
14-
self, id, country, province, coordinates, last_updated, confirmed, deaths, recovered
14+
self,
15+
id,
16+
country,
17+
province,
18+
coordinates,
19+
last_updated,
20+
confirmed,
21+
deaths,
22+
recovered,
1523
): # pylint: disable=too-many-arguments
1624
# General info.
1725
self.id = id
@@ -35,7 +43,9 @@ def country_code(self):
3543
:returns: The country code.
3644
:rtype: str
3745
"""
38-
return (countries.country_code(self.country) or countries.DEFAULT_COUNTRY_CODE).upper()
46+
return (
47+
countries.country_code(self.country) or countries.DEFAULT_COUNTRY_CODE
48+
).upper()
3949

4050
@property
4151
def country_population(self):
@@ -66,7 +76,11 @@ def serialize(self):
6676
# Last updated.
6777
"last_updated": self.last_updated,
6878
# Latest data (statistics).
69-
"latest": {"confirmed": self.confirmed, "deaths": self.deaths, "recovered": self.recovered},
79+
"latest": {
80+
"confirmed": self.confirmed,
81+
"deaths": self.deaths,
82+
"recovered": self.recovered,
83+
},
7084
}
7185

7286

app/location/csbs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def __init__(self, id, state, county, coordinates, last_updated, confirmed, deat
2525
self.state = state
2626
self.county = county
2727

28-
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
28+
def serialize(
29+
self, timelines=False
30+
): # pylint: disable=arguments-differ,unused-argument
2931
"""
3032
Serializes the location into a dict.
3133

app/location/nyt.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def __init__(self, id, state, county, coordinates, last_updated, timelines):
1414
self.state = state
1515
self.county = county
1616

17-
def serialize(self, timelines=False): # pylint: disable=arguments-differ,unused-argument
17+
def serialize(
18+
self, timelines=False
19+
): # pylint: disable=arguments-differ,unused-argument
1820
"""
1921
Serializes the location into a dict.
2022

app/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949

5050
# Enable CORS.
5151
APP.add_middleware(
52-
CORSMiddleware, allow_credentials=True, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"],
52+
CORSMiddleware,
53+
allow_credentials=True,
54+
allow_origins=["*"],
55+
allow_methods=["*"],
56+
allow_headers=["*"],
5357
)
5458
APP.add_middleware(GZipMiddleware, minimum_size=1000)
5559

app/routers/v1.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ async def all_categories():
1919
"deaths": deaths,
2020
"recovered": recovered,
2121
# Latest.
22-
"latest": {"confirmed": confirmed["latest"], "deaths": deaths["latest"], "recovered": recovered["latest"],},
22+
"latest": {
23+
"confirmed": confirmed["latest"],
24+
"deaths": deaths["latest"],
25+
"recovered": recovered["latest"],
26+
},
2327
}
2428

2529

app/routers/v2.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class Sources(str, enum.Enum):
2020

2121

2222
@V2.get("/latest", response_model=LatestResponse)
23-
async def get_latest(request: Request, source: Sources = "jhu"): # pylint: disable=unused-argument
23+
async def get_latest(
24+
request: Request, source: Sources = "jhu"
25+
): # pylint: disable=unused-argument
2426
"""
2527
Getting latest amount of total confirmed cases, deaths, and recoveries.
2628
"""
@@ -35,7 +37,9 @@ async def get_latest(request: Request, source: Sources = "jhu"): # pylint: disa
3537

3638

3739
# pylint: disable=unused-argument,too-many-arguments,redefined-builtin
38-
@V2.get("/locations", response_model=LocationsResponse, response_model_exclude_unset=True)
40+
@V2.get(
41+
"/locations", response_model=LocationsResponse, response_model_exclude_unset=True
42+
)
3943
async def get_locations(
4044
request: Request,
4145
source: Sources = "jhu",
@@ -65,11 +69,18 @@ async def get_locations(
6569

6670
# Do filtering.
6771
try:
68-
locations = [location for location in locations if str(getattr(location, key)).lower() == str(value)]
72+
locations = [
73+
location
74+
for location in locations
75+
if str(getattr(location, key)).lower() == str(value)
76+
]
6977
except AttributeError:
7078
pass
7179
if not locations:
72-
raise HTTPException(404, detail=f"Source `{source}` does not have the desired location data.")
80+
raise HTTPException(
81+
404,
82+
detail=f"Source `{source}` does not have the desired location data.",
83+
)
7384

7485
# Return final serialized data.
7586
return {
@@ -84,7 +95,9 @@ async def get_locations(
8495

8596
# pylint: disable=invalid-name
8697
@V2.get("/locations/{id}", response_model=LocationResponse)
87-
async def get_location_by_id(request: Request, id: int, source: Sources = "jhu", timelines: bool = True):
98+
async def get_location_by_id(
99+
request: Request, id: int, source: Sources = "jhu", timelines: bool = True
100+
):
88101
"""
89102
Getting specific location by id.
90103
"""

app/services/location/csbs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ async def get_locations():
6464
continue
6565

6666
# Coordinates.
67-
coordinates = Coordinates(item["Latitude"], item["Longitude"]) # pylint: disable=unused-variable
67+
coordinates = Coordinates(
68+
item["Latitude"], item["Longitude"]
69+
) # pylint: disable=unused-variable
6870

6971
# Date string without "EDT" at end.
7072
last_update = " ".join(item["Last Update"].split(" ")[0:2])

app/services/location/jhu.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ async def get(self, loc_id): # pylint: disable=arguments-differ
4141

4242

4343
# Base URL for fetching category.
44-
BASE_URL = (
45-
"https://raw.githubusercontent.com/CSSEGISandData/2019-nCoV/master/csse_covid_19_data/csse_covid_19_time_series/"
46-
)
44+
BASE_URL = "https://raw.githubusercontent.com/CSSEGISandData/2019-nCoV/master/csse_covid_19_data/csse_covid_19_time_series/"
4745

4846

4947
@cached(cache=TTLCache(maxsize=4, ttl=1800))
@@ -84,7 +82,9 @@ async def get_category(category):
8482

8583
for item in data:
8684
# Filter out all the dates.
87-
dates = dict(filter(lambda element: date_util.is_date(element[0]), item.items()))
85+
dates = dict(
86+
filter(lambda element: date_util.is_date(element[0]), item.items())
87+
)
8888

8989
# Make location history from dates.
9090
history = {date: int(amount or 0) for date, amount in dates.items()}
@@ -178,13 +178,15 @@ async def get_locations():
178178
{
179179
"confirmed": Timeline(
180180
{
181-
datetime.strptime(date, "%m/%d/%y").isoformat() + "Z": amount
181+
datetime.strptime(date, "%m/%d/%y").isoformat()
182+
+ "Z": amount
182183
for date, amount in timelines["confirmed"].items()
183184
}
184185
),
185186
"deaths": Timeline(
186187
{
187-
datetime.strptime(date, "%m/%d/%y").isoformat() + "Z": amount
188+
datetime.strptime(date, "%m/%d/%y").isoformat()
189+
+ "Z": amount
188190
for date, amount in timelines["deaths"].items()
189191
}
190192
),

0 commit comments

Comments
 (0)