Skip to content
Closed
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ __Sample response__
"id": 39,
"country": "Norway",
"country_code": "NO",
"continent_codes_list": ["EUR"],
"country_population": 5009150,
"province": "",
"county": "",
Expand Down Expand Up @@ -175,6 +176,7 @@ __Sample response__
"id": 0,
"country": "Thailand",
"country_code": "TH",
"continent_codes_list": ["ASI"],
"country_population": 67089500,
"province": "",
"county": "",
Expand All @@ -192,6 +194,7 @@ __Sample response__
{
"id": 39,
"country": "Norway",
"continent_codes_list": ["EUR"],
"country_code": "NO",
"province": "",
"county": "",
Expand Down Expand Up @@ -254,6 +257,7 @@ __Sample Response__
"id": 16,
"country": "Italy",
"country_code": "IT",
"continent_codes_list": ["EUR"],
"country_population": 60340328,
"province": "",
"county": "",
Expand Down Expand Up @@ -294,6 +298,7 @@ __Sample Response__
"id": 0,
"country": "US",
"country_code": "US",
"continent_codes_list": ["NAC"],
"country_population": 310232863,
"province": "New York",
"state": "New York",
Expand All @@ -313,6 +318,7 @@ __Sample Response__
"id": 1,
"country": "US",
"country_code": "US",
"continent_codes_list": ["NAC"],
"country_population": 310232863,
"province": "New York",
"state": "New York",
Expand Down
20 changes: 17 additions & 3 deletions app/location/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ..coordinates import Coordinates
from ..utils import countries
from ..utils import continents, countries
from ..utils.populations import country_population


Expand All @@ -26,12 +26,25 @@ def __init__(self, id, country, province, coordinates, last_updated, confirmed,
@property
def country_code(self):
"""
Gets the alpha-2 code represention of the country. Returns 'XX' if none is found.
Gets the alpha-2 code representation of the country. Returns 'XX' if none is found.

:returns: The country code.
:rtype: str
"""
return (countries.country_code(self.country) or countries.default_country_code).upper()
return countries.country_code(self.country) or countries.default_country_code

@property
def continent_codes_list(self):
"""
Gets the alpha-3 code representations of the continent codes where the
country represented by the country code is located. Returns 'CCC' if
none is found.

:returns: The list of continent codes.
:rtype: list
"""
country_code = countries.country_code(self.country)
return continents.continent_codes_list(country_code) or continents.default_continent_codes_list

@property
def country_population(self):
Expand All @@ -55,6 +68,7 @@ def serialize(self):
"id": self.id,
"country": self.country,
"country_code": self.country_code,
"continent_codes_list": self.continent_codes_list,
"country_population": self.country_population,
"province": self.province,
# Coordinates.
Expand Down
1 change: 1 addition & 0 deletions app/models/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Location(BaseModel):
id: int
country: str
country_code: str
continent_codes_list: list = []
country_population: int = None
province: str = ""
county: str = ""
Expand Down
1 change: 1 addition & 0 deletions app/router/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def get_locations(
request: Request,
source: Sources = "jhu",
country_code: str = None,
continent_codes_list: list = [],
province: str = None,
county: str = None,
timelines: bool = False,
Expand Down
7 changes: 5 additions & 2 deletions app/services/location/jhu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ...coordinates import Coordinates
from ...location import TimelinedLocation
from ...timeline import Timeline
from ...utils import countries
from ...utils import continents, countries
from ...utils import date as date_util
from . import LocationService

Expand Down Expand Up @@ -75,12 +75,15 @@ def get_category(category):
# Latest data insert value.
latest = list(history.values())[-1]

country_code = countries.country_code(country)

# Normalize the item and append to locations.
locations.append(
{
# General info.
"country": country,
"country_code": countries.country_code(country),
"country_code": country_code,
"continent_codes_list": continents.continent_codes_list(country_code),
"province": item["Province/State"],
# Coordinates.
"coordinates": {"lat": item["Lat"], "long": item["Long"],},
Expand Down
Loading