-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
17 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
"""Generate valid country codes and names.""" | ||
from enum import Enum | ||
|
||
import pycountry | ||
from iso3166 import countries | ||
|
||
ALPHA_2_CODE = [(country.alpha_2, country.alpha_2) for country in pycountry.countries] | ||
|
||
def get_country_flags(): | ||
"""Generate Unicode flags for all ISO 3166-1 alpha-2 country codes in Alpha2 Enum.""" | ||
base = ord('🇦') | ||
return {code.name: chr(base + ord(code.name[0]) - ord('A')) + chr(base + ord(code.name[1]) - ord('A')) for code in Alpha2} | ||
|
||
ALPHA_2_CODE = [(country.alpha2, country.alpha2) for country in countries] | ||
Alpha2 = Enum("Alpha_2", ALPHA_2_CODE) # type:ignore | ||
|
||
ALPHA_3_CODE = [(country.alpha_3, country.alpha_3) for country in pycountry.countries] | ||
Alpha3 = Enum("Alpha_2", ALPHA_3_CODE) # type:ignore | ||
ALPHA_3_CODE = [(country.alpha3, country.alpha3) for country in countries] | ||
Alpha3 = Enum("Alpha_3", ALPHA_3_CODE) # type:ignore | ||
|
||
NUMERIC_CODE = [(country.numeric, country.numeric) for country in pycountry.countries] | ||
NUMERIC_CODE = [(str(country.numeric), str(country.numeric)) for country in countries] | ||
Numeric = Enum("Numeric_code", NUMERIC_CODE) # type:ignore | ||
|
||
NAME = [(country.name, country.name) for country in pycountry.countries] | ||
NAME = [(country.name, country.name) for country in countries] | ||
Name = Enum("Name", NAME) # type:ignore | ||
|
||
FLAG = [(country.flag, country.flag) for country in pycountry.countries] | ||
Flag = Enum("Flag", FLAG) # type:ignore | ||
flag_mapping = get_country_flags() | ||
FLAG = [(flag, flag) for code, flag in flag_mapping.items()] | ||
Flag = Enum("Flag", FLAG) # type:ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters