Skip to content

Commit 163c238

Browse files
committed
formatting
1 parent fb8abdf commit 163c238

File tree

14 files changed

+30
-80
lines changed

14 files changed

+30
-80
lines changed

app/location/__init__.py

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

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

5040
@property
5141
def country_population(self):

app/location/csbs.py

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

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

app/location/nyt.py

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

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

app/routers/v2.py

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

2121

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

3836

3937
# pylint: disable=unused-argument,too-many-arguments,redefined-builtin
40-
@V2.get(
41-
"/locations", response_model=LocationsResponse, response_model_exclude_unset=True
42-
)
38+
@V2.get("/locations", response_model=LocationsResponse, response_model_exclude_unset=True)
4339
async def get_locations(
4440
request: Request,
4541
source: Sources = "jhu",
@@ -78,8 +74,7 @@ async def get_locations(
7874
pass
7975
if not locations:
8076
raise HTTPException(
81-
404,
82-
detail=f"Source `{source}` does not have the desired location data.",
77+
404, detail=f"Source `{source}` does not have the desired location data.",
8378
)
8479

8580
# Return final serialized data.

app/services/location/csbs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from asyncache import cached
77
from cachetools import TTLCache
88

9-
109
from ...caches import check_cache, load_cache
1110
from ...coordinates import Coordinates
1211
from ...location.csbs import CSBSLocation

app/services/location/jhu.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ async def get_category(category):
8282

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

8987
# Make location history from dates.
9088
history = {date: int(amount or 0) for date, amount in dates.items()}
@@ -178,15 +176,13 @@ async def get_locations():
178176
{
179177
"confirmed": Timeline(
180178
{
181-
datetime.strptime(date, "%m/%d/%y").isoformat()
182-
+ "Z": amount
179+
datetime.strptime(date, "%m/%d/%y").isoformat() + "Z": amount
183180
for date, amount in timelines["confirmed"].items()
184181
}
185182
),
186183
"deaths": Timeline(
187184
{
188-
datetime.strptime(date, "%m/%d/%y").isoformat()
189-
+ "Z": amount
185+
datetime.strptime(date, "%m/%d/%y").isoformat() + "Z": amount
190186
for date, amount in timelines["deaths"].items()
191187
}
192188
),

app/services/location/nyt.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from asyncache import cached
77
from cachetools import TTLCache
88

9-
109
from ...caches import check_cache, load_cache
1110
from ...coordinates import Coordinates
1211
from ...location.nyt import NYTLocation
@@ -37,9 +36,7 @@ async def get(self, loc_id): # pylint: disable=arguments-differ
3736

3837

3938
# Base URL for fetching category.
40-
BASE_URL = (
41-
"https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv"
42-
)
39+
BASE_URL = "https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv"
4340

4441

4542
def get_grouped_locations_dict(data):
@@ -107,9 +104,7 @@ async def get_locations():
107104
# Make location history for confirmed and deaths from dates.
108105
# List is tuples of (date, amount) in order of increasing dates.
109106
confirmed_list = histories["confirmed"]
110-
confirmed_history = {
111-
date: int(amount or 0) for date, amount in confirmed_list
112-
}
107+
confirmed_history = {date: int(amount or 0) for date, amount in confirmed_list}
113108

114109
deaths_list = histories["deaths"]
115110
deaths_history = {date: int(amount or 0) for date, amount in deaths_list}
@@ -120,23 +115,18 @@ async def get_locations():
120115
id=idx,
121116
state=county_state[1],
122117
county=county_state[0],
123-
coordinates=Coordinates(
124-
None, None
125-
), # NYT does not provide coordinates
126-
last_updated=datetime.utcnow().isoformat()
127-
+ "Z", # since last request
118+
coordinates=Coordinates(None, None), # NYT does not provide coordinates
119+
last_updated=datetime.utcnow().isoformat() + "Z", # since last request
128120
timelines={
129121
"confirmed": Timeline(
130122
{
131-
datetime.strptime(date, "%Y-%m-%d").isoformat()
132-
+ "Z": amount
123+
datetime.strptime(date, "%Y-%m-%d").isoformat() + "Z": amount
133124
for date, amount in confirmed_history.items()
134125
}
135126
),
136127
"deaths": Timeline(
137128
{
138-
datetime.strptime(date, "%Y-%m-%d").isoformat()
139-
+ "Z": amount
129+
datetime.strptime(date, "%Y-%m-%d").isoformat() + "Z": amount
140130
for date, amount in deaths_history.items()
141131
}
142132
),

app/utils/populations.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,17 @@ def fetch_populations(save=False):
2828

2929
# Fetch the countries.
3030
try:
31-
countries = requests.get(
32-
GEONAMES_URL, params={"username": "dperic"}, timeout=1.25
33-
).json()["geonames"]
31+
countries = requests.get(GEONAMES_URL, params={"username": "dperic"}, timeout=1.25).json()[
32+
"geonames"
33+
]
3434
# Go through all the countries and perform the mapping.
3535
for country in countries:
36-
mappings.update(
37-
{country["countryCode"]: int(country["population"]) or None}
38-
)
36+
mappings.update({country["countryCode"]: int(country["population"]) or None})
3937

4038
if mappings and save:
41-
LOGGER.info(
42-
f"Saving population data to {app.io.save(GEONAMES_BACKUP_PATH, mappings)}"
43-
)
39+
LOGGER.info(f"Saving population data to {app.io.save(GEONAMES_BACKUP_PATH, mappings)}")
4440
except (json.JSONDecodeError, KeyError, requests.exceptions.Timeout) as err:
45-
LOGGER.warning(
46-
f"Error pulling population data. {err.__class__.__name__}: {err}"
47-
)
41+
LOGGER.warning(f"Error pulling population data. {err.__class__.__name__}: {err}")
4842
mappings = app.io.load(GEONAMES_BACKUP_PATH)
4943
LOGGER.info(f"Using backup data from {GEONAMES_BACKUP_PATH}")
5044
# Finally, return the mappings.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.black]
2-
line-length = 88
2+
line-length = 100
33
target-version = ['py36', 'py37', 'py38']
44
include = '\.pyi?$'
55
exclude = '''
@@ -23,7 +23,7 @@ multi_line_output = 3
2323
include_trailing_comma = "True"
2424
force_grid_wrap = 0
2525
use_parentheses = "True"
26-
line_length = 88
26+
line_length = 100
2727

2828
[tool.pylint.master]
2929
extension-pkg-whitelist = "pydantic"
@@ -42,7 +42,7 @@ logging-modules = "logging"
4242
allow-wildcard-with-all = "no"
4343
[tool.pylint.format]
4444
indent-after-paren = "4"
45-
max-line-length = "120" # matches black setting
45+
max-line-length = "100" # matches black setting
4646
max-module-lines = "800"
4747
no-space-check = '''
4848
trailing-comma,

tasks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def fmt(ctx, targets="."):
3333

3434

3535
@invoke.task
36-
def check(
37-
ctx, fmt=False, sort=False, diff=False
38-
): # pylint: disable=redefined-outer-name
36+
def check(ctx, fmt=False, sort=False, diff=False): # pylint: disable=redefined-outer-name
3937
"""Check code format and import order."""
4038
if not any([fmt, sort]):
4139
fmt = True

0 commit comments

Comments
 (0)