forked from freddier/Horarios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhorarios.py
71 lines (60 loc) · 2.05 KB
/
horarios.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: UTF-8 -*-
# 👆 Sin lo de arriba no se puede poner emojis
import pytz
import datetime
# Mi script asume la hora de tu PC
date_to_convert = "2020-11-17 21:00:00"
# Recuerda: Es la hora de tu PC
date_to_convert = datetime.datetime.strptime(
date_to_convert, "%Y-%m-%d %H:%M:%S")
print(date_to_convert)
print("Generando bloque de banderas:")
print("")
# En orden de tamaño de mercado/prioridad
zones = [
["🇲🇽", "America/Mexico_City"],
["🇨🇴", "America/Bogota"],
["🇵🇪", "America/Lima"],
["🇨🇱", "America/Santiago"],
["🇦🇷", "America/Buenos_Aires"],
["🇪🇸", "Europe/Madrid"],
["🇺🇾", "America/Montevideo"],
["🇪🇨", "America/Guayaquil"],
["🇬🇹", "America/Guatemala"],
["🇸🇻", "America/El_Salvador"],
["🇧🇴", "America/La_Paz"],
["🇵🇾", "America/Asuncion"],
["🇩🇴", "America/Santo_Domingo"],
["🇵🇦", "America/Panama"],
["🇨🇷", "America/Costa_Rica"],
["🇭🇳", "America/Tegucigalpa"],
["🇻🇪", "America/Caracas"],
["🇳🇮", "America/Managua"],
["🇨🇺", "Cuba"],
["🇺🇸", "US/Pacific"]
]
# Inicializamos el diccionario
times = {"00pm": "X"}
# If you need Brazil:
# ["🇧🇷","America/Sao_Paulo"]
# Los timezones no están derivados de países, sino de ciudades.
# Aunque la prioridad es por país
for country in zones:
dtc = date_to_convert.astimezone(pytz.timezone(country[1]))
if country[1] == "Europe/Madrid":
# Imprime la hora en formato de 24 horas y una "H" al final
dtc = dtc.strftime("%-HH")
else:
# Imprime la hora en formato de 12 horas PM/AM
dtc = dtc.strftime("%-I%p")
try:
times[dtc] = times[dtc] + country[0]
except KeyError:
times[dtc] = country[0]
# Si el país es USA en Pacific, agregar el "PT" frente a bandera de US
if country[1] == "US/Pacific":
times[dtc] = times[dtc] + " PT"
times[dtc] = times[dtc] + " "
for t, c in times.items():
if c != "X":
print(t.lower(), c.strip())