File tree Expand file tree Collapse file tree 3 files changed +9
-0
lines changed
Expand file tree Collapse file tree 3 files changed +9
-0
lines changed Original file line number Diff line number Diff line change 1212# Base URL to make requests against.
1313API_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".
1721COUNTRY_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 )
Original file line number Diff line number Diff 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" ] == "$"
Original file line number Diff line number Diff 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" ] == "$"
You can’t perform that action at this time.
0 commit comments