-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
89 lines (74 loc) · 2.18 KB
/
Copy pathmain.py
File metadata and controls
89 lines (74 loc) · 2.18 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
#!/usr/bin/env python3
"""
main.py — Belo Horizonte weather terminal
Usage: python main.py
"""
import sys
try:
from rich.console import Console
from rich.rule import Rule
from rich.prompt import Prompt
except ImportError:
print("Missing dependency. Run: pip install rich")
sys.exit(1)
from services.weather_service import (
screen_agora,
screen_temperatura,
screen_umidade,
screen_vento,
screen_chuva,
screen_previsao,
clear,
)
console = Console()
COMMANDS = {
"agora": "resumo completo agora",
"temperatura": "temperatura atual",
"umidade": "umidade relativa do ar",
"vento": "velocidade do vento",
"chuva": "probabilidade de chuva hora a hora",
"previsao": "previsão dos próximos 7 dias",
}
SCREENS = {
"agora": screen_agora,
"temperatura": screen_temperatura,
"umidade": screen_umidade,
"vento": screen_vento,
"chuva": screen_chuva,
"previsao": screen_previsao,
}
def show_menu():
clear()
console.print(f" [dim]fonte: Open-Meteo · dados em tempo real[/dim]")
console.print()
for cmd, desc in COMMANDS.items():
console.print(f" [bold white]{cmd:<14}[/bold white] [dim]{desc}[/dim]")
console.print()
console.print(f" [dim]{'exit':<14} fechar[/dim]")
console.print()
def main():
while True:
show_menu()
choice = Prompt.ask("[dim]>[/dim]").strip().lower()
if not choice:
continue
if choice == "exit":
console.print()
console.print("[dim] weatherterm disable[/dim]")
console.print()
break
if choice in SCREENS:
result = SCREENS[choice]()
if result == "exit":
console.print()
console.print("[dim] weatherterm disable[/dim]")
console.print()
break
else:
console.print(f"\n [red]comando desconhecido: {choice}[/red]")
Prompt.ask("[dim] enter para continuar[/dim]")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
console.print("\n\n[dim] weatherterm disable[/dim]\n")