-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalerta.py
More file actions
65 lines (56 loc) · 1.84 KB
/
alerta.py
File metadata and controls
65 lines (56 loc) · 1.84 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
"""
Faça um script que pergunta ao usuário qual a temperatura atual e o indice de umidade do ar sendo que caso
será exibida uma mensagem de alerta dependendo das condições:
temp maior 45: "ALERTA!!! 🥵 Perigo calor extremo"
temp maior que 30 e temp vezes 3 for maior ou igual a umidade:
"ALERTA!!! 🥵♒ Perigo de calor úmido"
temp entre 10 e 30: "😀 Normal"
temp entre 0 e 10: "🥶 Frio"
temp <0: "ALERTA!!! ⛄ Frio Extremo."
ex:
python3 temp.py
temperatura: 30
umidade: 90
...
'ALERTA!!! 🥵 Perigo calor extremo'
"""
import os
import logging
log_level = os.getenv("LOG_LEVEL", "WARNING").upper()
log = logging.Logger("jose", log_level)
ch = logging.StreamHandler()
ch.setLevel(log_level)
fmt = logging.Formatter(
'%(asctime)s %(name)s %(levelname)s '
'l:%(lineno)d f:%(filename)s: %(message)s'
)
ch.setFormatter(fmt)
log.addHandler(ch)
# TODO: Mover para modúlo de utilidades
def read_inputs():
"""Inputs of user for main."""
try:
temperature = float(input("Insert the temperature: "))
humidity = float(input("Insert the humidity: "))
except ValueError as e:
log.error("Insert number float or integer - %s", str(e))
return temperature, humidity
while True:
temperature, humidity = read_inputs()
if temperature > 45.0:
msg = "ALERTA!!! 🥵 Perigo calor extremo"
elif temperature > 30.0 and (temperature * 3) >= humidity:
msg = "ALERTA!!! 🥵♒ Perigo de calor úmido"
elif 10 <= temperature and temperature <= 30:
msg = "😀 Normal"
elif 0 <= temperature and temperature < 10:
msg = "🥶 Frio"
elif temperature < 0:
msg = "ALERTA!!! ⛄ Frio Extremo."
print(
f"temperature: {temperature}\n"
f"humidity: {humidity}\n"
f"{msg}"
)
if input("Press Enter for continue or any key for stop!"):
break