Fix: Download ID

This commit is contained in:
2026-04-26 16:39:04 +02:00
parent 5ca7adc1f2
commit e8e4cce689
+38 -20
View File
@@ -670,37 +670,55 @@ def global_cmd():
return jsonify({"success": True}) return jsonify({"success": True})
def auto_update_ids(): def auto_update_ids():
while True: """Versione corretta: controlla all'avvio e poi ogni notte."""
def download_logic():
try: try:
# Usiamo esattamente i nomi e le URL definiti nel tuo config/codice
with open(CONFIG_PATH, 'r') as f: with open(CONFIG_PATH, 'r') as f:
current_cfg = json.load(f) current_cfg = json.load(f)
target_time = current_cfg.get("update_schedule", "03:00")
urls = current_cfg.get("id_urls", { urls = current_cfg.get("id_urls", {
"dmr": "https://radioid.net/static/users.csv", "dmr": "https://radioid.net/static/users.csv",
"nxdn": "https://radioid.net/static/nxdn.csv" "nxdn": "https://radioid.net/static/nxdn.csv"
}) })
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}
logger.info("📡 Inizio download database ID (DMR e NXDN)...")
# Download DMR -> dmrid.dat
req_dmr = urllib.request.Request(urls["dmr"], headers=headers)
with urllib.request.urlopen(req_dmr) as response, open(DMR_IDS_PATH, 'wb') as out_file:
out_file.write(response.read())
# Download NXDN -> nxdn.csv
req_nxdn = urllib.request.Request(urls["nxdn"], headers=headers)
with urllib.request.urlopen(req_nxdn) as response, open(NXDN_IDS_PATH, 'wb') as out_file:
out_file.write(response.read())
load_ids()
logger.info("✅ Aggiornamento completato con successo.")
except Exception as e:
logger.error(f"❌ Errore durante il download: {e}")
# --- CONTROLLO INIZIALE ALL'AVVIO ---
if not os.path.exists(DMR_IDS_PATH) or not os.path.exists(NXDN_IDS_PATH):
logger.info("🔍 File ID mancanti. Avvio download immediato...")
download_logic()
# --- CICLO NOTTURNO ---
while True:
try:
now = time.strftime("%H:%M") now = time.strftime("%H:%M")
with open(CONFIG_PATH, 'r') as f:
target_time = json.load(f).get("update_schedule", "03:00")
if now == target_time: if now == target_time:
logger.info(f">>> [AUTO-UPDATE] Scheduled time reached ({now}). Downloading...") logger.info(f"⏰ Orario programmato ({target_time}) raggiunto. Aggiorno...")
download_logic()
# Trucco: Camuffiamo Python da browser per bypassare i blocchi Cloudflare
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'}
# Download DMR
req_dmr = urllib.request.Request(urls["dmr"], headers=headers)
with urllib.request.urlopen(req_dmr) as response, open(DMR_IDS_PATH, 'wb') as out_file:
out_file.write(response.read())
# Download NXDN
req_nxdn = urllib.request.Request(urls["nxdn"], headers=headers)
with urllib.request.urlopen(req_nxdn) as response, open(NXDN_IDS_PATH, 'wb') as out_file:
out_file.write(response.read())
load_ids()
logger.info(f">>> [AUTO-UPDATE] Completed successfully.")
time.sleep(65) time.sleep(65)
except Exception as e: except Exception as e:
logger.error(f">>> [AUTO-UPDATE] Error: {e}") logger.error(f"⚠️ Errore nel thread update: {e}")
time.sleep(30) time.sleep(30)
@app.route('/api/ui_config', methods=['GET']) @app.route('/api/ui_config', methods=['GET'])