-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreloj.py
More file actions
97 lines (77 loc) · 2.08 KB
/
Copy pathreloj.py
File metadata and controls
97 lines (77 loc) · 2.08 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import pyttsx3
import msvcrt
from datetime import datetime
from num2words import num2words
engine = pyttsx3.init()
dias_semana = [
"Lunes",
"Martes",
"Miércoles",
"Jueves",
"Viernes",
"Sábado",
"Domingo"
]
meses = [
"Enero",
"Febrero",
"Marzo",
"Abril",
"Mayo",
"Junio",
"Julio",
"Agosto",
"Septiembre",
"Octubre",
"Noviembre",
"Diciembre"
]
def anunciar_hora():
ahora = datetime.now()
hora_texto = num2words(ahora.hour, lang="es")
minutos_texto = num2words(ahora.minute, lang="es")
segundos_texto = num2words(ahora.second, lang="es")
mensaje = (
f"La hora actual es {hora_texto} horas, "
f"{minutos_texto} minutos y {segundos_texto} segundos."
)
engine.say(mensaje)
engine.runAndWait()
def anunciar_fecha():
ahora = datetime.now()
dia_semana = dias_semana[ahora.weekday()]
dia_numero = ahora.day
mes = meses[ahora.month - 1]
anio = ahora.year
semana = ahora.isocalendar()[1]
dia_texto = num2words(dia_numero, lang="es")
anio_texto = num2words(anio, lang="es")
semana_texto = num2words(semana, lang="es")
mensaje = (
f"Hoy es {dia_semana} {dia_texto} de {mes} de {anio_texto}. "
f"Estamos en la semana número {semana_texto} del año."
)
engine.say(mensaje)
engine.runAndWait()
engine.say("Reloj accesible iniciado.")
engine.say("Presione h para la hora, f para la fecha o s para salir.")
engine.runAndWait()
print("Reloj accesible iniciado.")
print("Presione: H = Hora | F = Fecha | S = Salir")
while True:
tecla = msvcrt.getch()
if tecla in (b'\x00', b'\xe0'):
msvcrt.getch()
continue
try:
tecla = tecla.decode("utf-8").lower()
except UnicodeDecodeError:
continue
if tecla == "h":
anunciar_hora()
elif tecla == "f":
anunciar_fecha()
elif tecla == "s":
engine.say("Programa finalizado.")
engine.runAndWait()
break