diff --git a/foss42/data/geo/country.py b/foss42/data/geo/country.py index 032c2b5..ff00903 100644 --- a/foss42/data/geo/country.py +++ b/foss42/data/geo/country.py @@ -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'], @@ -1390,3 +1410,4 @@ "CH": SUB_CH, } +