|
2 | 2 | Utilities used in handlers. |
3 | 3 | """ |
4 | 4 |
|
| 5 | +import copy |
5 | 6 | import json |
6 | 7 | import os |
7 | 8 | import sys |
8 | | -import copy |
9 | 9 |
|
10 | 10 | from .version import SDK_VERSION |
11 | 11 |
|
@@ -68,21 +68,18 @@ def format_details( |
68 | 68 | """ |
69 | 69 | Format details given a countries object. |
70 | 70 | """ |
71 | | - details["country_name"] = countries.get(details.get("country")) |
72 | | - details["isEU"] = details.get("country") in eu_countries |
73 | | - details["country_flag_url"] = ( |
74 | | - COUNTRY_FLAGS_URL + (details.get("country") or "") + ".svg" |
75 | | - ) |
76 | | - details["country_flag"] = copy.deepcopy( |
77 | | - countries_flags.get(details.get("country")) |
78 | | - ) |
79 | | - details["country_currency"] = copy.deepcopy( |
80 | | - countries_currencies.get(details.get("country")) |
81 | | - ) |
82 | | - details["continent"] = copy.deepcopy( |
83 | | - continents.get(details.get("country")) |
84 | | - ) |
85 | | - details["latitude"], details["longitude"] = read_coords(details.get("loc")) |
| 71 | + country = details.get("country") |
| 72 | + if country_name := countries.get(country): |
| 73 | + details["country_name"] = country_name |
| 74 | + details["isEU"] = country in eu_countries |
| 75 | + details["country_flag_url"] = COUNTRY_FLAGS_URL + (country or "") + ".svg" |
| 76 | + details["country_flag"] = copy.deepcopy(countries_flags.get(details.get("country"))) |
| 77 | + if currency := details.get("country"): |
| 78 | + details["country_currency"] = copy.deepcopy(countries_currencies.get(currency)) |
| 79 | + if continent := continents.get(country): |
| 80 | + details["continent"] = copy.deepcopy(continent) |
| 81 | + if location := details.get("loc"): |
| 82 | + details["latitude"], details["longitude"] = read_coords(location) |
86 | 83 |
|
87 | 84 |
|
88 | 85 | def read_coords(location): |
|
0 commit comments