Backup automatico script del 2026-01-18 07:00
This commit is contained in:
@@ -199,8 +199,12 @@ def call_meteo_script(args_list):
|
||||
try:
|
||||
# Esegui: python3 meteo.py --arg1 val1 ...
|
||||
cmd = ["python3", METEO_SCRIPT] + args_list
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
||||
# Timeout aumentato a 90s per gestire retry e chiamate API multiple
|
||||
# (get_forecast può fare retry + fallback, get_visibility_forecast può fare 2 chiamate)
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=90)
|
||||
return result.stdout if result.returncode == 0 else f"Errore Script: {result.stderr}"
|
||||
except subprocess.TimeoutExpired:
|
||||
return f"Errore esecuzione script: Timeout dopo 90 secondi (script troppo lento)"
|
||||
except Exception as e:
|
||||
return f"Errore esecuzione script: {e}"
|
||||
|
||||
@@ -270,7 +274,7 @@ async def meteo_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> N
|
||||
f"✈️ **Report Meteo - {viaggio_attivo['name']}**\n\n{report_viaggio}",
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
else:
|
||||
else:
|
||||
# Nessun viaggio attivo: invia report per Casa
|
||||
await update.message.reply_text("🔄 Generazione report meteo per Casa...", parse_mode="Markdown")
|
||||
report_casa = call_meteo_script(["--home"])
|
||||
@@ -661,7 +665,7 @@ async def meteo_viaggio_command(update: Update, context: ContextTypes.DEFAULT_TY
|
||||
f"📊 **Report Meteo - {name}**\n\n{report_meteo}",
|
||||
parse_mode="Markdown"
|
||||
)
|
||||
else:
|
||||
else:
|
||||
await update.message.reply_text(
|
||||
f"⚠️ Errore nella generazione del report meteo:\n{report_meteo}",
|
||||
parse_mode="Markdown"
|
||||
@@ -729,11 +733,13 @@ async def meteo_viaggio_command(update: Update, context: ContextTypes.DEFAULT_TY
|
||||
await update.message.reply_text(f"❌ Errore durante l'elaborazione: {str(e)}", parse_mode="Markdown")
|
||||
|
||||
async def scheduled_morning_report(context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
# LANCIAMO LO SCRIPT ESTERNO PER CASA
|
||||
# Esegui una sola chiamata e invia il report a tutti i chat_id
|
||||
report = call_meteo_script(["--home"])
|
||||
for uid in ALLOWED_IDS:
|
||||
try: await context.bot.send_message(chat_id=uid, text=report, parse_mode="Markdown")
|
||||
except: pass
|
||||
try:
|
||||
await context.bot.send_message(chat_id=uid, text=report, parse_mode="Markdown")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@restricted
|
||||
async def button_handler(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
@@ -838,7 +844,7 @@ def main():
|
||||
application.add_handler(CallbackQueryHandler(button_handler))
|
||||
|
||||
job_queue = application.job_queue
|
||||
job_queue.run_daily(scheduled_morning_report, time=datetime.time(hour=8, minute=0, tzinfo=TZINFO), days=(0, 1, 2, 3, 4, 5, 6))
|
||||
job_queue.run_daily(scheduled_morning_report, time=datetime.time(hour=7, minute=15, tzinfo=TZINFO), days=(0, 1, 2, 3, 4, 5, 6))
|
||||
|
||||
application.run_polling()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user