vacation day fix
This commit is contained in:
@@ -1,8 +1,3 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: Namespace
|
|
||||||
metadata:
|
|
||||||
name: glance-system
|
|
||||||
---
|
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
@@ -52,6 +47,7 @@ data:
|
|||||||
app.py: |
|
app.py: |
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import re
|
||||||
from typing import List, Dict, Any, Optional
|
from typing import List, Dict, Any, Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -139,17 +135,34 @@ data:
|
|||||||
|
|
||||||
# Daily columns (bottom forecast table: .ik.daily-forecast-container .ik.dailyForecastCol)
|
# Daily columns (bottom forecast table: .ik.daily-forecast-container .ik.dailyForecastCol)
|
||||||
daily: List[Dict[str, Any]] = []
|
daily: List[Dict[str, Any]] = []
|
||||||
for col in soup.select(".ik.daily-forecast-container .ik.dailyForecastCol")[:7]:
|
for col in soup.select(".ik.daily-forecast-container .ik.dailyForecastCol")[:15]:
|
||||||
dow_el = col.select_one(".ik.dfDay")
|
dow_el = col.select_one(".ik.dfDay")
|
||||||
icon_el = col.select_one("img.ik.forecast-icon")
|
icon_el = col.select_one("img.ik.forecast-icon")
|
||||||
|
|
||||||
|
# Normal structure (most days)
|
||||||
tmax_el = col.select_one("div.ik.max")
|
tmax_el = col.select_one("div.ik.max")
|
||||||
tmin_el = col.select_one("div.ik.min")
|
tmin_el = col.select_one("div.ik.min")
|
||||||
|
|
||||||
dow = dow_el.get_text(strip=True) if dow_el else ""
|
dow = dow_el.get_text(strip=True) if dow_el else ""
|
||||||
icon = _abs_url(icon_el.get("src") if icon_el else None)
|
icon = _abs_url(icon_el.get("src") if icon_el else None)
|
||||||
|
|
||||||
tmax = _to_int_temp(tmax_el.get_text(strip=True) if tmax_el else "")
|
tmax = _to_int_temp(tmax_el.get_text(strip=True) if tmax_el else "")
|
||||||
tmin = _to_int_temp(tmin_el.get_text(strip=True) if tmin_el else "")
|
tmin = _to_int_temp(tmin_el.get_text(strip=True) if tmin_el else "")
|
||||||
|
|
||||||
|
# Fallback structure (e.g. "vacation" days) where div.ik.max/min are missing
|
||||||
|
# In those cases the visible temps are usually the first two numeric <a> texts
|
||||||
|
# inside .ik.min-max-container (order: max, min).
|
||||||
|
if tmax is None or tmin is None:
|
||||||
|
vals: List[str] = []
|
||||||
|
for a in col.select(".ik.min-max-container a"):
|
||||||
|
txt = a.get_text(strip=True)
|
||||||
|
if re.fullmatch(r"-?\d+", txt or ""):
|
||||||
|
vals.append(txt)
|
||||||
|
|
||||||
|
if len(vals) >= 2:
|
||||||
|
tmax = _to_int_temp(vals[0])
|
||||||
|
tmin = _to_int_temp(vals[1])
|
||||||
|
|
||||||
# Keep only rows that look valid
|
# Keep only rows that look valid
|
||||||
if dow and (tmin is not None) and (tmax is not None):
|
if dow and (tmin is not None) and (tmax is not None):
|
||||||
daily.append(
|
daily.append(
|
||||||
@@ -161,7 +174,7 @@ data:
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Limit to 5 days for your widget
|
# Limit to 5 days for your widget (first 5 columns in the table, including "vacation" days)
|
||||||
daily = daily[:5]
|
daily = daily[:5]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user