superguardado: fixes pi_bot (offset persistente, unit systemd) + voz.py (desconectar chromecast) + lecciones 27-31
This commit is contained in:
@@ -9,6 +9,7 @@ import requests
|
||||
|
||||
BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
LOG = os.path.join(BASE, "bot.log")
|
||||
OFFSET_FILE = os.path.join(BASE, "bot.offset")
|
||||
TV_API = "http://127.0.0.1:8600/tv/mensaje"
|
||||
|
||||
|
||||
@@ -174,13 +175,29 @@ def monitor_temperatura():
|
||||
f"(límite {ALERTA_TEMP}°C)\n{msg}", CHAT_ID)
|
||||
|
||||
|
||||
def cargar_offset():
|
||||
try:
|
||||
with open(OFFSET_FILE) as f:
|
||||
return int(f.read().strip())
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def guardar_offset(offset):
|
||||
try:
|
||||
with open(OFFSET_FILE, "w") as f:
|
||||
f.write(str(offset))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
if not TOKEN:
|
||||
print("Falta TELEGRAM_TOKEN en .env")
|
||||
return
|
||||
threading.Thread(target=monitor_temperatura, daemon=True).start()
|
||||
offset = None
|
||||
log("Bot iniciado")
|
||||
offset = cargar_offset()
|
||||
log("Bot iniciado" + (f" (offset {offset})" if offset else ""))
|
||||
print("Bot iniciado. Esperando mensajes...")
|
||||
while True:
|
||||
try:
|
||||
@@ -193,6 +210,7 @@ def main():
|
||||
).json()
|
||||
for upd in r.get("result", []):
|
||||
offset = upd["update_id"] + 1
|
||||
guardar_offset(offset)
|
||||
log(f"UPDATE {upd.get('update_id')}")
|
||||
msg = upd.get("message") or upd.get("channel_post")
|
||||
if not msg:
|
||||
|
||||
Reference in New Issue
Block a user