idokep teszt 2
This commit is contained in:
@@ -365,69 +365,90 @@ data:
|
||||
- type: split-column
|
||||
max-columns: 3
|
||||
widgets:
|
||||
# Weather Widget
|
||||
# Weather Widget - Időkép Scraper
|
||||
- type: custom-api
|
||||
url: https://www.idokep.hu/idojaras/Budapest
|
||||
cache: 15m
|
||||
style:
|
||||
grid-column: span 4
|
||||
grid-row: span 3
|
||||
template: |
|
||||
{{/* Extract Current Weather Data */}}
|
||||
{{ $body := .Body }}
|
||||
{{ $temp := findSubmatch `(?s)current-temperature">([^˚<]+)` $body }}
|
||||
{{ $condition := findSubmatch `(?s)current-weather">([^<]+)</div>` $body }}
|
||||
{{ $icon := findSubmatch `(?s)forecast-bigicon"[^>]+src="([^"]+)"` $body }}
|
||||
{{ $sunrise := findSubmatch `Napkelte ([0-9:]+)` $body }}
|
||||
{{ $sunset := findSubmatch `Napnyugta ([0-9:]+)` $body }}
|
||||
url: https://www.idokep.hu/idojaras/Budapest
|
||||
cache: 15m
|
||||
style:
|
||||
grid-column: span 4
|
||||
grid-row: span 3
|
||||
template: |
|
||||
{{/* 1. Extract Current Data */}}
|
||||
{{ $body := .Body }}
|
||||
{{ $temp := findSubmatch `(?s)current-temperature">([^˚<]+)` $body | trimSpace }}
|
||||
{{ $cond := findSubmatch `(?s)current-weather">([^<]+)</div>` $body | trimSpace }}
|
||||
{{ $icon := findSubmatch `(?s)forecast-bigicon"[^>]+src="([^"]+)"` $body }}
|
||||
{{ $sunrise := findSubmatch `Napkelte ([0-9:]+)` $body }}
|
||||
{{ $sunset := findSubmatch `Napnyugta ([0-9:]+)` $body }}
|
||||
|
||||
<div class="flex flex-col h-full p-4 text-white" style="background: rgba(0, 0, 0, 0.2); border-radius: 1rem;">
|
||||
{{/* Header: Location and Current Time */}}
|
||||
<div class="flex justify-between items-start mb-4">
|
||||
<div>
|
||||
<h2 class="text-xl font-bold">Budapest</h2>
|
||||
<p class="text-sm opacity-80">{{ now | formatTime "Monday, Jan 02" }}</p>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<div class="flex items-center gap-2 text-xs opacity-70">
|
||||
<span>↑ {{ $sunrise }}</span>
|
||||
<span>↓ {{ $sunset }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/* 2. Extract Daily Forecast (Regex patterns for specific day indices) */}}
|
||||
{{/* Day 1 */}}
|
||||
{{ $d1_pat := `(?s)dailyForecastCol.*?dfDayNum">([0-9]+).*?dfDay">([^<]+).*?src="([^"]+)".*?max[^>]+>([^<]+)</a>.*?min[^>]+>([^<]+)</a>` }}
|
||||
{{ $d1_num := findSubmatch $d1_pat $body }}
|
||||
{{ $d1_day := index (findSubmatch $d1_pat $body) 1 }}
|
||||
{{ $d1_icon := index (findSubmatch $d1_pat $body) 2 }}
|
||||
{{ $d1_max := index (findSubmatch $d1_pat $body) 3 }}
|
||||
{{ $d1_min := index (findSubmatch $d1_pat $body) 4 }}
|
||||
|
||||
{{/* Main Current Weather Display */}}
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<div class="flex items-center gap-4">
|
||||
<img src="https://www.idokep.hu{{ $icon }}" class="w-16 h-16 object-contain" alt="weather icon">
|
||||
<div>
|
||||
<div class="text-4xl font-extrabold">{{ $temp }}°C</div>
|
||||
<div class="text-md font-medium opacity-90">{{ $condition }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/* Day 2 (skipping 1 column) */}}
|
||||
{{ $d2_pat := `(?s)dailyForecastCol.*?dailyForecastCol.*?dfDayNum">([0-9]+).*?dfDay">([^<]+).*?src="([^"]+)".*?max[^>]+>([^<]+)</a>.*?min[^>]+>([^<]+)</a>` }}
|
||||
{{ $d2_day := index (findSubmatch $d2_pat $body) 1 }}
|
||||
{{ $d2_icon := index (findSubmatch $d2_pat $body) 2 }}
|
||||
{{ $d2_max := index (findSubmatch $d2_pat $body) 3 }}
|
||||
{{ $d2_min := index (findSubmatch $d2_pat $body) 4 }}
|
||||
|
||||
{{/* Daily Forecast Section (Next 5 Days) */}}
|
||||
<div class="flex flex-col gap-3 mt-auto border-t border-white/10 pt-4">
|
||||
{{/* Helper to extract a specific day's data using regex index-based groups is limited in Go templates,
|
||||
so we extract the forecast block and manually grab the first few days. */}}
|
||||
<style>
|
||||
.idokep-container { background: rgba(0, 0, 0, 0.25); border-radius: 1rem; padding: 1.5rem; color: #fff; font-family: sans-serif; height: 100%; display: flex; flex-direction: column; }
|
||||
.idokep-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; }
|
||||
.idokep-main { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
|
||||
.idokep-temp { font-size: 3.5rem; font-weight: 800; line-height: 1; }
|
||||
.idokep-subinfo { display: flex; gap: 1rem; font-size: 0.8rem; opacity: 0.7; margin-bottom: 1rem; }
|
||||
.forecast-row { display: grid; grid-template-columns: 3rem 2rem 2.5rem 1fr 2.5rem; align-items: center; gap: 0.75rem; padding: 0.4rem 0; border-top: 1px solid rgba(255,255,255,0.1); }
|
||||
.temp-bar { height: 6px; border-radius: 3px; background: linear-gradient(90deg, #4ade80, #fbbf24, #f87171); opacity: 0.8; }
|
||||
</style>
|
||||
|
||||
{{ range $i := (list 1 2 3 4 5) }}
|
||||
{{/* This logic identifies the columns in the daily forecast grid */}}
|
||||
{{ $dayPattern := printf `(?s)dailyForecastCol.*?dfDayNum">([0-9]+).*?dfDay">([^<]+).*?src="([^"]+)".*?max[^>]+>([^<]+)</a>.*?min[^>]+>([^<]+)</a>` }}
|
||||
{{/* Note: Standard Glance regex findSubmatch returns the first match. To get multiple days,
|
||||
we'd ideally need a loop. Since Glance regex is for single matches,
|
||||
we'll use the current logic to display the next primary data points. */}}
|
||||
{{ end }}
|
||||
<div class="idokep-container">
|
||||
<div class="idokep-header">
|
||||
<div>
|
||||
<div class="text-xl font-bold uppercase tracking-wide">Budapest</div>
|
||||
<div class="text-xs opacity-60">{{ now | formatTime "Monday, Jan 02" }}</div>
|
||||
</div>
|
||||
<div class="idokep-temp">{{ $temp }}°</div>
|
||||
</div>
|
||||
|
||||
{{/* Fallback to detailed view link if scraping multiple days is too complex for standard regex */}}
|
||||
<div class="text-center">
|
||||
<a href="https://www.idokep.hu/elorejelzes/Budapest" class="text-xs uppercase tracking-widest font-bold opacity-60 hover:opacity-100 transition-opacity">
|
||||
Részletes Előrejelzés →
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="idokep-main">
|
||||
<div class="flex items-center gap-4">
|
||||
<img src="https://www.idokep.hu{{ $icon }}" class="w-16 h-16" alt="weather">
|
||||
<div class="text-lg font-medium">{{ $cond }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="idokep-subinfo">
|
||||
<span><i class="fas fa-sun"></i> ↑ {{ $sunrise }}</span>
|
||||
<span><i class="fas fa-moon"></i> ↓ {{ $sunset }}</span>
|
||||
</div>
|
||||
|
||||
{{/* Daily Forecast Rows (Day 1 and 2 shown as examples) */}}
|
||||
<div class="forecast-row">
|
||||
<span class="font-bold">{{ $d1_day }}</span>
|
||||
<img src="https://www.idokep.hu{{ $d1_icon }}" class="w-6 h-6">
|
||||
<span class="text-right text-xs">{{ $d1_min }}°</span>
|
||||
<div class="temp-bar"></div>
|
||||
<span class="font-bold text-xs">{{ $d1_max }}°</span>
|
||||
</div>
|
||||
|
||||
<div class="forecast-row">
|
||||
<span class="font-bold">{{ $d2_day }}</span>
|
||||
<img src="https://www.idokep.hu{{ $d2_icon }}" class="w-6 h-6">
|
||||
<span class="text-right text-xs">{{ $d2_min }}°</span>
|
||||
<div class="temp-bar" style="width: 80%"></div>
|
||||
<span class="font-bold text-xs">{{ $d2_max }}°</span>
|
||||
</div>
|
||||
|
||||
<div class="mt-auto pt-4 text-center">
|
||||
<a href="https://www.idokep.hu/elorejelzes/Budapest" class="text-[10px] uppercase opacity-40 hover:opacity-100 transition-opacity">idokep.hu 30 napos →</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
# Calendar Widget
|
||||
- type: calendar
|
||||
|
||||
Reference in New Issue
Block a user