my.calendar.holidays: unhardcode calendar, detect it from the location data
This commit is contained in:
parent
bdb5dcd221
commit
96113ad5ae
5 changed files with 49 additions and 7 deletions
|
@ -15,3 +15,18 @@ tz_lookup['UTC'] = pytz.utc # ugh. otherwise it'z Zulu...
|
|||
@lru_cache(None)
|
||||
def abbr_to_timezone(abbr: str) -> tzinfo:
|
||||
return tz_lookup[abbr]
|
||||
|
||||
|
||||
def zone_to_countrycode(zone: str) -> str:
|
||||
# todo make optional?
|
||||
return _zones_to_countrycode()[zone]
|
||||
|
||||
|
||||
@lru_cache(1)
|
||||
def _zones_to_countrycode():
|
||||
# https://stackoverflow.com/a/13020785/706389
|
||||
res = {}
|
||||
for countrycode, timezones in pytz.country_timezones.items():
|
||||
for timezone in timezones:
|
||||
res[timezone] = countrycode
|
||||
return res
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue