Skip to content

Commit 28a3af1

Browse files
author
awaismslm
committed
Added Country flags image link
1 parent f591515 commit 28a3af1

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

ipinfo/handler_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
# Base URL to make requests against.
1313
API_URL = "https://ipinfo.io"
1414

15+
# Base URL to get country flag image link.
16+
# "PK" -> "https://cdn.ipinfo.io/static/images/countries-flags/PK.svg"
17+
COUNTRY_FLAGS_URL = "https://cdn.ipinfo.io/static/images/countries-flags/"
18+
1519
# Used to transform incoming responses with country abbreviations into the full
1620
# expanded country name, e.g. "PK" -> "Pakistan".
1721
COUNTRY_FILE_DEFAULT = "countries.json"
@@ -75,6 +79,7 @@ def format_details(
7579
"""
7680
details["country_name"] = countries.get(details.get("country"))
7781
details["isEU"] = details.get("country") in eu_countries
82+
details["country_flag_url"] = COUNTRY_FLAGS_URL + details.get("country") + ".svg"
7883
details["country_flag"] = copy.deepcopy(
7984
countries_flags.get(details.get("country"))
8085
)

tests/handler_async_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ async def test_get_details():
4747
country_flag = details.country_flag
4848
assert country_flag["emoji"] == "🇺🇸"
4949
assert country_flag["unicode"] == "U+1F1FA U+1F1F8"
50+
country_flag_url = details.country_flag_url
51+
assert country_flag_url == "https://cdn.ipinfo.io/static/images/countries-flags/US.svg"
5052
country_currency = details.country_currency
5153
assert country_currency["code"] == "USD"
5254
assert country_currency["symbol"] == "$"

tests/handler_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def test_get_details():
4444
country_flag = details.country_flag
4545
assert country_flag["emoji"] == "🇺🇸"
4646
assert country_flag["unicode"] == "U+1F1FA U+1F1F8"
47+
country_flag_url = details.country_flag_url
48+
assert country_flag_url == "https://cdn.ipinfo.io/static/images/countries-flags/US.svg"
4749
country_currency = details.country_currency
4850
assert country_currency["code"] == "USD"
4951
assert country_currency["symbol"] == "$"

0 commit comments

Comments
 (0)