added tooltips for icons
This commit is contained in:
@@ -37,6 +37,67 @@ data:
|
||||
SCRAPES = Counter("idokep_scrapes_total", "Total Időkép scrapes", ["place", "status"])
|
||||
SCRAPE_SECONDS = Histogram("idokep_scrape_seconds", "Időkép scrape duration in seconds", ["place"])
|
||||
|
||||
ICON_CONDITIONS = {
|
||||
# Daytime (0xx)
|
||||
"010": "Derült",
|
||||
"011": "Pára",
|
||||
"021": "Gyengén felhős",
|
||||
"022": "Közepesen felhős",
|
||||
"023": "Erősen felhős",
|
||||
"030": "Borult",
|
||||
"040": "Ködszitálás",
|
||||
"041": "Szitálás",
|
||||
"042": "Gyenge eső",
|
||||
"043": "Eső",
|
||||
"043s": "Eső viharos széllel",
|
||||
"051": "Havas eső",
|
||||
"052": "Ónos eső",
|
||||
"061": "Havazás",
|
||||
"062": "Havazás",
|
||||
"081": "Zápor",
|
||||
"083": "Hózápor",
|
||||
"088": "Jégeső",
|
||||
"090": "Zivatar",
|
||||
"092": "Száraz zivatar",
|
||||
"100": "Köd",
|
||||
"101": "Porvihar",
|
||||
# Nighttime (3xx) - same conditions
|
||||
"310": "Derült",
|
||||
"311": "Pára",
|
||||
"321": "Gyengén felhős",
|
||||
"322": "Közepesen felhős",
|
||||
"323": "Erősen felhős",
|
||||
"330": "Borult",
|
||||
"340": "Ködszitálás",
|
||||
"341": "Szitálás",
|
||||
"342": "Gyenge eső",
|
||||
"343": "Eső",
|
||||
"343s": "Eső viharos széllel",
|
||||
"351": "Havas eső",
|
||||
"352": "Ónos eső",
|
||||
"361": "Havazás",
|
||||
"362": "Havazás",
|
||||
"381": "Zápor",
|
||||
"383": "Hózápor",
|
||||
"388": "Jégeső",
|
||||
"390": "Zivatar",
|
||||
"392": "Száraz zivatar",
|
||||
"400": "Köd",
|
||||
"401": "Porvihar",
|
||||
}
|
||||
|
||||
def _icon_condition(icon_url: str) -> str:
|
||||
"""Extract weather condition from icon URL."""
|
||||
if not icon_url:
|
||||
return ""
|
||||
# URL format: https://www.idokep.hu/assets/icons/XXX.png
|
||||
import re
|
||||
match = re.search(r'/(\d{3}s?)\.png', icon_url)
|
||||
if match:
|
||||
code = match.group(1)
|
||||
return ICON_CONDITIONS.get(code, "")
|
||||
return ""
|
||||
|
||||
def _abs_url(url): return "https://www.idokep.hu" + url if url and not url.startswith("http") else url
|
||||
def _to_float(s):
|
||||
try: return float(s.strip().replace("˚C", "").replace("°C", "").replace("°", "").replace(",", "."))
|
||||
@@ -112,7 +173,8 @@ data:
|
||||
hourly.append({
|
||||
"time": t.get_text(strip=True),
|
||||
"temp_c": _to_float(temp.get_text(strip=True)),
|
||||
"icon_url": _abs_url(icon.get("src"))
|
||||
"icon_url": _abs_url(icon.get("src")),
|
||||
"condition": _icon_condition(_abs_url(icon.get("src"))
|
||||
})
|
||||
|
||||
# Daily
|
||||
@@ -142,6 +204,7 @@ data:
|
||||
"tmin_c": v_tmin,
|
||||
"tmax_c": v_tmax,
|
||||
"icon_url": _abs_url(icon.get("src") if icon else None),
|
||||
"condition": _icon_condition(icon_url),
|
||||
})
|
||||
|
||||
daily = _calculate_gradient_data(daily[:5])
|
||||
|
||||
@@ -715,7 +715,7 @@ data:
|
||||
{{ range $i, $h := $hourly }}
|
||||
<div class="idokep-hour">
|
||||
<div class="idokep-hour-time">{{ $h.String "time" }}</div>
|
||||
{{ if $h.String "icon_url" }}<img class="idokep-hour-icon" src="{{ $h.String "icon_url" }}" alt="" />{{ end }}
|
||||
{{ if $h.String "icon_url" }}<img class="idokep-hour-icon" src="{{ $h.String "icon_url" }}" title="{{ $h.String "condition" }}" alt="{{ $h.String "condition" }}" />{{ end }}
|
||||
<div class="idokep-hour-temp">{{ printf "%.0f" ($h.Float "temp_c") }}°</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
@@ -731,7 +731,7 @@ data:
|
||||
<span class="idokep-daynum">{{ .String "daynum" }}</span>
|
||||
</div>
|
||||
<div class="idokep-dayicon">
|
||||
{{ if .String "icon_url" }}<img src="{{ .String "icon_url" }}" alt="" />{{ end }}
|
||||
{{ if .String "icon_url" }}<img src="{{ .String "icon_url" }}" title="{{ .String "condition" }}" alt="{{ .String "condition" }}" />{{ end }}
|
||||
</div>
|
||||
<div class="idokep-min">{{ printf "%.0f" (.Float "tmin_c") }}°</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user