diff options
| author | Tyler Hoang <tyler@tylerhoang.xyz> | 2026-05-06 12:21:26 -0700 |
|---|---|---|
| committer | Tyler Hoang <tyler@tylerhoang.xyz> | 2026-05-06 12:21:26 -0700 |
| commit | e708bec6cd76c2686de4158dde4d04f72a3c300d (patch) | |
| tree | 04b0bc4738e090dd7834d47478c7e652da010f92 /services/countries.py | |
init: lumiere film diary
Diffstat (limited to 'services/countries.py')
| -rw-r--r-- | services/countries.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/services/countries.py b/services/countries.py new file mode 100644 index 0000000..8681e81 --- /dev/null +++ b/services/countries.py @@ -0,0 +1,67 @@ +COUNTRY_NAME_TO_ISO_NUMERIC = { + "argentina": 32, + "australia": 36, + "belgium": 56, + "brazil": 76, + "bulgaria": 100, + "canada": 124, + "china": 156, + "czech republic": 203, + "denmark": 208, + "finland": 246, + "france": 250, + "germany": 276, + "hong kong": 344, + "hungary": 348, + "india": 356, + "iran": 364, + "ireland": 372, + "italy": 380, + "japan": 392, + "luxembourg": 442, + "netherlands": 528, + "new zealand": 554, + "norway": 578, + "northern ireland": 826, + "russia": 643, + "soviet union": 643, + "spain": 724, + "south africa": 710, + "south korea": 410, + "korea, south": 410, + "republic of korea": 410, + "sweden": 752, + "taiwan": 158, + "thailand": 764, + "united arab emirates": 784, + "united kingdom": 826, + "uk": 826, + "great britain": 826, + "england": 826, + "scotland": 826, + "united states": 840, + "united states of america": 840, + "usa": 840, +} + +ISO_NUMERIC_TO_COUNTRY_NAME = { + value: key.title() for key, value in COUNTRY_NAME_TO_ISO_NUMERIC.items() +} +ISO_NUMERIC_TO_COUNTRY_NAME[410] = "South Korea" +ISO_NUMERIC_TO_COUNTRY_NAME[643] = "Russia" +ISO_NUMERIC_TO_COUNTRY_NAME[826] = "United Kingdom" +ISO_NUMERIC_TO_COUNTRY_NAME[840] = "United States of America" + + +def split_country_names(value: str | None) -> list[str]: + if not value: + return [] + + normalized = value.replace(";", ",") + return [item.strip() for item in normalized.split(",") if item.strip()] + + +def country_name_to_iso_numeric(value: str | None) -> int | None: + if not value: + return None + return COUNTRY_NAME_TO_ISO_NUMERIC.get(value.casefold().strip()) |
