Backup automatico script del 2026-07-19 07:00
This commit is contained in:
@@ -113,16 +113,34 @@ def get_bot_token():
|
||||
def get_coordinates(query):
|
||||
if not query or query.lower() == "casa":
|
||||
return DEFAULT_LAT, DEFAULT_LON, DEFAULT_NAME, "SM"
|
||||
q = query.strip()
|
||||
try:
|
||||
from loogle_core.geo_parse import resolve_place_query
|
||||
except ImportError:
|
||||
try:
|
||||
from geo_parse import resolve_place_query
|
||||
except ImportError:
|
||||
resolve_place_query = None
|
||||
if resolve_place_query:
|
||||
place = resolve_place_query(q)
|
||||
if place:
|
||||
return (
|
||||
place["lat"],
|
||||
place["lon"],
|
||||
place.get("name") or f"{place['lat']:.5f}, {place['lon']:.5f}",
|
||||
place.get("country_code") or "IT",
|
||||
)
|
||||
return None, None, None, None
|
||||
url = "https://geocoding-api.open-meteo.com/v1/search"
|
||||
try:
|
||||
resp = open_meteo_get(url, params={"name": query, "count": 1, "language": "it", "format": "json"}, timeout=(5, 10))
|
||||
resp = open_meteo_get(url, params={"name": q, "count": 1, "language": "it", "format": "json"}, timeout=(5, 10))
|
||||
res = resp.json().get("results", [])
|
||||
if res:
|
||||
res = res[0]
|
||||
cc = res.get("country_code", "IT").upper()
|
||||
name = f"{res.get('name')} ({cc})"
|
||||
return res['latitude'], res['longitude'], name, cc
|
||||
except:
|
||||
except Exception:
|
||||
pass
|
||||
return None, None, None, None
|
||||
|
||||
@@ -1141,7 +1159,7 @@ def _apply_unified_precip(hourly: Dict, daily: Dict, casa: bool) -> Tuple[Dict,
|
||||
return hourly, daily
|
||||
|
||||
|
||||
def format_weather_context_report(models_data, location_name, country_code, as_json=False):
|
||||
def format_weather_context_report(models_data, location_name, country_code, as_json=False, lat=None, lon=None):
|
||||
"""Genera report contestuale intelligente con ensemble multi-modello"""
|
||||
# Combina modelli a breve e lungo termine
|
||||
merged_data = merge_multi_model_forecast(models_data, forecast_days=10)
|
||||
@@ -1761,6 +1779,8 @@ def format_weather_context_report(models_data, location_name, country_code, as_j
|
||||
return {
|
||||
"location": location_name,
|
||||
"country_code": country_code,
|
||||
"lat": lat,
|
||||
"lon": lon,
|
||||
"models": models_used,
|
||||
"trend_html": trend_explanation if trend else "",
|
||||
"weather_changes": weather_changes,
|
||||
@@ -1781,6 +1801,13 @@ def format_weather_context_report(models_data, location_name, country_code, as_j
|
||||
return "\n".join(msg_parts)
|
||||
|
||||
def send_telegram(text, chat_id, token, debug_mode=False):
|
||||
try:
|
||||
from telegram_gate import telegram_alerts_enabled
|
||||
except ImportError:
|
||||
telegram_alerts_enabled = lambda: True # type: ignore
|
||||
|
||||
if not telegram_alerts_enabled():
|
||||
return False
|
||||
if not token:
|
||||
return False
|
||||
url = f"https://api.telegram.org/bot{token}/sendMessage"
|
||||
@@ -1858,11 +1885,11 @@ def main():
|
||||
|
||||
# Genera report
|
||||
if args.json:
|
||||
payload = format_weather_context_report(models_data, name, cc, as_json=True)
|
||||
payload = format_weather_context_report(models_data, name, cc, as_json=True, lat=lat, lon=lon)
|
||||
print(json.dumps(payload, ensure_ascii=False))
|
||||
return
|
||||
|
||||
report = format_weather_context_report(models_data, name, cc)
|
||||
report = format_weather_context_report(models_data, name, cc, lat=lat, lon=lon)
|
||||
|
||||
if debug_mode:
|
||||
report = f"🛠 <b>[DEBUG MODE]</b> 🛠\n\n{report}"
|
||||
|
||||
Reference in New Issue
Block a user