Skip to content
Open
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
21 changes: 21 additions & 0 deletions foss42/data/geo/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,26 @@
{KEY_ALPHA2: 'XK', KEY_INTL_PHONE_CODE: '383'}
]

phone_map = {item[KEY_ALPHA2]: item for item in PHONE_DATA}

for country in COUNTRY_CODES:
code_info = phone_map.get(country[KEY_ALPHA2])
if code_info:
country[KEY_INTL_PHONE_CODE] = code_info.get(KEY_INTL_PHONE_CODE)
country[KEY_AREA_PHONE_CODE] = code_info.get(KEY_AREA_PHONE_CODE, [])
def get_phone_by_name(country_name):
country_name = country_name.lower()
for country in COUNTRY_CODES:
# Popular name ya Official name dono check karega
if (country.get(KEY_POPULAR_NAME, "").lower() == country_name or
country[KEY_NAME].lower() == country_name):
return country.get(KEY_INTL_PHONE_CODE, "Not Found")
return "Country not found"

print(f"India Phone Code: {get_country_phone_code('IN')}") # Output: 91
print(f"USA Phone Code: {get_country_phone_code('US')}") # Output: 1
print(f"UK Phone Code: {get_country_phone_code('GB')}") # Output: 44

# (Global, Region, Sub-region, Intermediate Region) : alpha2 code map

REGION_COUNTRY_MAP = {('World', None, None, None): ['AQ'],
Expand Down Expand Up @@ -1390,3 +1410,4 @@
"CH": SUB_CH,

}