Backup automatico script del 2026-01-11 07:00
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import sqlite3
|
||||
import os
|
||||
import datetime
|
||||
@@ -92,7 +93,12 @@ def load_bot_token() -> str:
|
||||
return tok.strip() if tok else ""
|
||||
|
||||
|
||||
def send_telegram_message(message: str) -> None:
|
||||
def send_telegram_message(message: str, chat_ids: Optional[List[str]] = None) -> None:
|
||||
"""
|
||||
Args:
|
||||
message: Messaggio da inviare
|
||||
chat_ids: Lista di chat IDs (default: TELEGRAM_CHAT_IDS)
|
||||
"""
|
||||
if not message:
|
||||
return
|
||||
|
||||
@@ -101,9 +107,12 @@ def send_telegram_message(message: str) -> None:
|
||||
LOGGER.error("Token Telegram mancante (env/file). Messaggio NON inviato.")
|
||||
return
|
||||
|
||||
if chat_ids is None:
|
||||
chat_ids = TELEGRAM_CHAT_IDS
|
||||
|
||||
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
|
||||
|
||||
for chat_id in TELEGRAM_CHAT_IDS:
|
||||
for chat_id in chat_ids:
|
||||
payload = {
|
||||
"chat_id": chat_id,
|
||||
"text": message,
|
||||
@@ -312,7 +321,7 @@ def generate_report(db_path: str) -> Optional[str]:
|
||||
return msg
|
||||
|
||||
|
||||
def main() -> None:
|
||||
def main(chat_ids: Optional[List[str]] = None) -> None:
|
||||
db_path = find_local_db_path()
|
||||
if not db_path:
|
||||
db_path = docker_copy_db_to_temp()
|
||||
@@ -329,10 +338,17 @@ def main() -> None:
|
||||
|
||||
report = generate_report(db_path)
|
||||
if report:
|
||||
send_telegram_message(report)
|
||||
send_telegram_message(report, chat_ids=chat_ids)
|
||||
else:
|
||||
LOGGER.info("Nessun report da inviare.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
parser = argparse.ArgumentParser(description="Daily report")
|
||||
parser.add_argument("--debug", action="store_true", help="Invia messaggi solo all'admin (chat ID: %s)" % TELEGRAM_CHAT_IDS[0])
|
||||
args = parser.parse_args()
|
||||
|
||||
# In modalità debug, invia solo al primo chat ID (admin)
|
||||
chat_ids = [TELEGRAM_CHAT_IDS[0]] if args.debug else None
|
||||
|
||||
main(chat_ids=chat_ids)
|
||||
|
||||
Reference in New Issue
Block a user