Last active
December 27, 2022 16:20
-
-
Save webserveis/f32f4b9417a4f80c48e7a2530b1a10d6 to your computer and use it in GitHub Desktop.
Script EventDate TimeZone
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
import datetime | |
from dateutil.tz import gettz | |
class RegionTZ: | |
def __init__(self, name, tz, flag=None): | |
self.name = name | |
self.tz = gettz(tz.strip()) | |
if flag is None: | |
flag = self.name | |
self.flag = flag | |
self.dateTime = None | |
self.time = None | |
list = [] | |
# For get TimeZone from Spain go to https://www.zeitverschiebung.net/es/city/3117735 | |
# in 'Zona Horaria' is the time zone string: Europe/Madrid | |
# For get a emoji flag, search in google: emoji flag <country name> | |
# copy paste in third param | |
# Spanish speaking countries/regions | |
list.append(RegionTZ('Spain', 'Europe/Madrid', '๐ช๐ธ' )) | |
list.append(RegionTZ('Islas Canarias', 'Atlantic/Canary', '๐ฎ๐จ' )) | |
list.append(RegionTZ('Mรฉxico', 'America/Mexico_City', '๐ฒ๐ฝ' )) | |
list.append(RegionTZ('Colombia', 'America/Bogota', '๐จ๐ด' )) | |
list.append(RegionTZ('Argentina', 'America/Argentina/Buenos_Aires', '๐ฆ๐ท' )) | |
list.append(RegionTZ('Peru', 'America/Lima', '๐ต๐ช' )) | |
list.append(RegionTZ('Venezuela', 'America/Caracas', '๐ป๐ช' )) | |
list.append(RegionTZ('Chile', 'America/Santiago', '๐จ๐ฑ' )) | |
list.append(RegionTZ('Guatemala', 'America/Guatemala', '๐ฌ๐น' )) | |
list.append(RegionTZ('Ecuador', 'America/Guayaquil', '๐ช๐จ' )) | |
list.append(RegionTZ('Cuba', 'America/Havana', '๐จ๐บ' )) | |
list.append(RegionTZ('Bolivia', 'America/La_Paz', '๐ง๐ด' )) | |
list.append(RegionTZ('Repรบblica Dominicana', 'America/Santo_Domingo', '๐ฉ๐ด' )) | |
list.append(RegionTZ('Honduras', 'America/Tegucigalpa', '๐ญ๐ณ' )) | |
list.append(RegionTZ('El Salvador', 'America/El_Salvador', '๐ธ๐ป' )) | |
list.append(RegionTZ('Paraguay', 'America/Asuncion', '๐ต๐พ' )) | |
list.append(RegionTZ('Nicaragua', 'America/Managua', '๐ณ๐ฎ' )) | |
list.append(RegionTZ('Costa Rica', 'America/Costa_Rica', '๐จ๐ท' )) | |
list.append(RegionTZ('Panamรก', 'America/Panama', '๐ต๐ฆ' )) | |
list.append(RegionTZ('Puerto Rico', 'America/Puerto_Rico', '๐ต๐ท' )) | |
list.append(RegionTZ('Uruguay', 'America/Montevideo', '๐บ๐พ' )) | |
# Others regions | |
list.append(RegionTZ('Brasil', 'America/Sao_Paulo', '๐ง๐ท' )) | |
list.append(RegionTZ('Portugal', 'Europe/Lisbon', '๐ต๐น' )) | |
list.append(RegionTZ('Marruecos', 'Africa/Casablanca', '๐ฒ๐ฆ' )) | |
list.append(RegionTZ('Andorra', 'Europe/Andorra', '๐ฆ๐ฉ' )) | |
list.append(RegionTZ('Gibraltar', 'Europe/Gibraltar', '๐ฌ๐ฎ' )) | |
list.append(RegionTZ('Italia', 'Europe/Rome', '๐ฎ๐น' )) | |
list.append(RegionTZ('Los Angeles', 'America/Los_Angeles', '๐บ๐ธ' )) | |
# Time Date Formats | |
t12h = '%I:%M %p' #05:00 PM | |
tc12h = '%I %p' #5 PM | |
t24h = '%H:%M' #17:00 | |
tc24h = '%HH' #17H | |
dt1 = '%Y-%m-%d' #2023-01-25 | |
dt2 = '%d-%m-%Y' #25-01-2023 | |
dt3 = '%d %b %Y' #24 Jan 2023 | |
#================= Edit Zone ================= | |
# For get TimeZone from Madrid go to https://www.zeitverschiebung.net/es/city/3117735 | |
# in 'Zona Horaria' is the time zone string: Europe/Madrid | |
# Set the event date in format Year, Month, Day, Hour, Minute, Second | |
# Create Event Date Time | |
event_tz = gettz('Europe/Madrid') | |
eventDate = datetime.datetime( | |
2023, 1, 8, 17, 0, 0, #YYYY,M,D,H,M,S | |
tzinfo=event_tz) | |
# Set output format for date and times | |
timeOut = tc24h | |
dateOut = dt2 | |
#============================================= | |
# Make TimeTable | |
for row in list: | |
row.datetime = eventDate.astimezone(row.tz).strftime('%Y-%m-%d %H:%M') | |
#print(row.flag, row.time ) | |
timeList = sorted(set(map(lambda n: n.datetime, list))) | |
print('Event date:', eventDate) | |
header = None | |
for t in timeList: | |
gList = filter(lambda x: x.datetime == t, list) | |
arr = map(lambda x: x.flag, gList) | |
flags = ''.join(arr) | |
dtObj = datetime.datetime.strptime(t, '%Y-%m-%d %H:%M') | |
if (header != dtObj.strftime(dateOut)): | |
header = dtObj.strftime(dateOut) | |
print() | |
print(header) | |
print(dtObj.strftime(timeOut), '- ' + flags ) # time and flags | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment