# Clone and setup git clone https://gitlab.com/demogun1/misc_scripts.git cd misc_scripts # Create Python 3.12 venv python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt # Preview reports locally (no deploy, no email) ./scripts/weather-forecast/weather-forecast.py --dry-run ./scripts/weather-history/weather-history.py --days 7 --dry-run ./scripts/headache-analyzer/headache-analyzer.py --dry-run # Run everything (dry-run) ./run-and-publish.py --dry-run # Run everything + deploy (verbose) ./run-and-publish.py --verbose
misc_scripts/
├── run-and-publish.py # Orchestrator: runs all scripts, generates site
├── run.sh # Wrapper: git pull + clean + generate + rsync (POSIX sh)
├── config.ini.example # Config template (DB creds, paths, thresholds)
├── .gitlab-ci.yml # CI: lint (ruff) → typecheck (mypy) → test (pytest) → redirect page
├── ruff.toml # Lint configuration
├── schema.sql # MySQL schema definition
├── requirements.txt # Python deps (markdown, pymysql)
├── tests/ # pytest test suite (59 tests)
│ ├── test_smoke.py # Syntax, imports, exclusion logic
│ ├── test_scoring.py # MAE, rain accuracy, forecast parsing
│ ├── test_shared.py # Config, model selector, haversine
│ ├── test_forecast_modules.py # fetch, risk, charts, render
│ └── test_current_weather.py # JS validation
├── api/
│ └── php/ # PHP API (runs on tarhely.com hosting)
│ ├── config.php.example # Template — real config.php is gitignored
│ ├── auth.php # Register, login, logout, rate limiting
│ ├── cities.php # City search, add, remove, reorder
│ ├── log-route.php # Route forecast log (auth required)
│ └── admin.php # Admin panel (HTTP Basic Auth, server-rendered)
├── scripts/
│ ├── weather-forecast/
│ │ ├── weather-forecast.py # Thin orchestrator (247 lines)
│ │ ├── fetch.py # API communication + parsing (179 lines)
│ │ ├── risk.py # Headache/pressure risk scoring (174 lines)
│ │ ├── charts.py # Chart.js generation + warnings (422 lines)
│ │ ├── render.py # HTML rendering (629 lines)
│ │ ├── summary.py # Weather summaries HU+EN (196 lines)
│ │ ├── template.html # Web template (Jinja-like {{placeholders}})
│ │ └── template-email.html # Email template (inline styles, no JS)
│ ├── weather-history/
│ │ ├── weather-history.py # History chart generator
│ │ └── template.html # Chart.js template
│ ├── model-validator/
│ │ ├── save-forecast.py # Daily snapshot saver (→ DB only)
│ │ ├── evaluate.py # Compare forecast vs actuals (→ DB)
│ │ ├── evaluate-routes.py # Score route feedback points (→ DB)
│ │ └── report.py # Generate rankings HTML + JSON (← DB)
│ └── headache-analyzer/
│ └── headache-analyzer.py
├── shared/
│ ├── __init__.py # get_base_styles() — unified CSS generator
│ ├── config.py # CITIES, thresholds, URLs
│ ├── config_loader.py # Reads config.ini (DB, paths, etc.)
│ ├── db.py # MySQL helper (all DB operations)
│ ├── model_selector.py # Adaptive model ranking engine (DB-backed)
│ ├── i18n.js # Client-side translations
│ └── headaches.py # Headache log (DB-backed)
└── public_html/ # Deployed web output + static assets
main is blocked. All changes require a Merge Request with passing pipeline.
| Stage | Tool | What it checks | Blocking? |
|---|---|---|---|
lint | ruff | Unused imports, undefined names, syntax errors | Yes |
typecheck | mypy | Type errors, None access, wrong argument types | Yes |
test | pytest (59 tests) | Unit tests + integration import smoke test | Yes |
deploy | GitLab Pages | Copy to Pages (only if all above pass) | — |
# Lint ruff check . # Type check mypy --ignore-missing-imports --no-strict-optional --check-untyped-defs shared/ scripts/model-validator/ scripts/weather-forecast/fetch.py # Tests pytest tests/ -v
git checkout -b feature/my-change # Create branch # ... make changes ... pytest tests/ -v # Run tests locally ruff check . # Lint locally git add -A && git commit -m "..." # Commit git push -u origin feature/my-change # Push (creates MR link) # → GitLab CI runs → merge when green
All shared settings live in shared/config.py:
# Cities: key → (display_name, latitude, longitude)
CITIES = {
"inarcs": ("Inárcs", 47.2667, 19.3500),
"budapest": ("Budapest", 47.4979, 19.0402),
"ivancsa": ("Iváncsa", 46.9833, 18.8167),
"gyal": ("Gyál", 47.3833, 19.2167),
}
DEFAULT_CITY = "inarcs"
# Risk thresholds
RISK_THRESHOLD_HIGH = 5
TEMP_HOT_THRESHOLD = 35
WIND_STRONG_THRESHOLD = 50
CITIES in shared/config.pypublic_html/index.htmldata/stations.json on first evaluate runThe system learns which model is best per location/parameter/horizon:
save-forecast.py stores daily snapshots (all models)evaluate.py compares forecasts against measured actualsmodel_selector.py aggregates errors → picks best modelKey parameters in shared/model_selector.py:
| Constant | Value | Meaning |
|---|---|---|
MIN_SAMPLES | 7 | Minimum evaluations to trust a ranking |
WINDOW_DAYS | 30 | Rolling window for ranking calculation |
SIGNIFICANCE_GAP | 5.0% | Minimum advantage to prefer one model over another |
Client-side EN/HU translation using shared/i18n.js:
<span data-i18n="forecast">Forecast</span>
The key "forecast" is looked up in the TRANSLATIONS dict.
<span data-i18n-en="Hot day, 30°C" data-i18n-hu="Kiadós kánikula, 30°C">Hot day, 30°C</span>
Both versions stored as attributes. Toggle simply swaps innerHTML.
TRANSLATIONS dict in shared/i18n.jsdata-i18n="key" to the HTML elementshared/i18n.js → public_html/i18n.jsPure JavaScript, no backend needed. APIs used:
| Service | Purpose | Limit |
|---|---|---|
| OSRM | Route calculation (distance, duration, polyline) | Fair use (free) |
| Open-Meteo | Weather forecast per waypoint (4 models) | 10,000/day |
| Nominatim | Geocoding + reverse geocoding | 1 req/sec |
| Leaflet + OSM | Map rendering | Unlimited |
Every route request stores all-model forecasts in localStorage. POSTs to /api/log-route.php on tarhely.com → saved to MySQL route_logs table → evaluated daily by evaluate-routes.py.
PHP API on tarhely.com + client-side JS. Users can register, login, and save favorite cities.
user.js (login modal, city manager) + live-forecast.js (instant forecast for new cities)users, sessions, cities, user_cities| File | Endpoint | Description |
|---|---|---|
auth.php | ?action=register|login|logout|me | User authentication |
cities.php | ?action=list|my|search|add|remove|reorder | City management |
log-route.php | POST | Route forecast log (public, rate limited) |
| File | Purpose |
|---|---|
user.js | Login/register modal, user menu, city manager, dynamic tabs, onboarding hints |
live-forecast.js | Client-side forecast for cities without generated pages (Open-Meteo direct) |
city-nav.js | Floating city switcher — side panel (desktop) + horizontal tabs (mobile) |
cities table (if new) + user_citieslive-forecast.js fetches from Open-Meteo (4 models) → renders inlineweather-forecast-miskolc.htmlWhen a city has ranking data, the forecast page highlights the winning model:
Two levels of parallelization for fast report generation:
fetch_all_models() uses ThreadPoolExecutor(max_workers=4) — all 8 models fetched simultaneously (~2s instead of ~16s)run-and-publish.py runs 2 cities in parallel via subprocess.Popen--all-periods flag — single 30d API call → renders 3d, 7d, 30d HTML files| Metric | Before | After |
|---|---|---|
| 7 cities total | ~200s | ~35s |
| History API calls (7 cities) | 21 | 7 |
| Max concurrent requests | 1 | 8 |
Floating city switcher that appears on all pages:
window.userCities → localStorage → API → defaultscities-updated custom event to re-render when user changes citiesHeadache events are stored in MySQL (headaches table). Manage via the admin panel or direct SQL:
-- Add entry
INSERT INTO headaches (date, time, severity, city, notes)
VALUES ('2026-08-14', '07:30', 2, 'inarcs', 'pressure drop');
-- Severity: 1 = mild, 2 = moderate, 3 = severe
-- City: optional (NULL = applies to all cities)
Admin panel: /api/admin.php → Headaches tab provides a form for adding/deleting entries without SQL.
The analyzer is city-independent — correlates each event with weather from the location at that time.
Templates use {{placeholder}} syntax (Python string replacement, not Jinja):
<h1>{{location}}</h1>
<div class="subtitle">{{generated_time}}</div>
<div class="summary">{{weather_summary}}</div>
Rules:
<script src="i18n.js"></script>data-i18n on elements that need translationdata-i18n-en + data-i18n-hu attributesAll pages share the same base styles from shared/__init__.py → get_base_styles(theme):
Page-specific CSS (tables, charts, cards) is added on top. Theme overrides come from theme.css using [data-theme="name"] selectors + CSS variables.
| Page | Style source | Notes |
|---|---|---|
| Forecast | get_base_styles() via template placeholder | Template: scripts/weather-forecast/template.html |
| History | get_base_styles() via template placeholder | Template: scripts/weather-history/template.html |
| Rankings | get_base_styles() in report.py | Generated by model-validator |
| Headache | get_base_styles() in analyzer script | Inline f-string template |
| Route Weather | CSS variables + theme.css | Standalone page, same visual structure |
Never add custom fonts or hardcoded gradients to page styles. Use the shared base styles + theme.css for consistent look.
| Requirement | Value |
|---|---|
| Python | 3.11+ (Pi: 3.13, build server: 3.12) |
| Dependencies | markdown, pymysql (pip) |
| Database | MySQL on tarhely.com (config.ini for credentials) |
| PHP (tarhely.com) | 8.x with PDO, bcrypt, json (standard cPanel) |
| SSL fix (corporate) | Handled in run.sh (SSL_CERT_FILE export) |
| Platform | Linux (GIT TS build server or Raspberry Pi 4) |
| Backup | Daily mysqldump cron → /opt/amfor-cast/backups/ (30-day retention) |
Self-contained PHP admin at /api/admin.php, protected by HTTP Basic Auth (separate from user system).
| Section | Function |
|---|---|
| Dashboard | DB row counts, last run time, stale data alerts |
| Users | User list with email, display name, login history |
| Cities | All tracked cities, user counts, default flags |
| Sessions | Active/expired sessions, revoke capability |
| Headaches | Add/delete entries via form |
| Routes | Pending vs evaluated route logs |
| Evaluations | Per-city coverage statistics |
| Gaps & Failures | Days with incomplete model data (<5/8 models) |
| Security | Login attempt monitoring, rate limit hits |
| Document | Description |
|---|---|
| 🚀 Operations & Release Guide | Cron, deployment, run.sh, RPi setup, troubleshooting |
| 🗺️ Unified Product Roadmap | Feature roadmap, architecture decisions, timeline |
Az Amfor-Cast egy moduláris Python rendszer, amely több forrásból gyűjt időjárási adatokat, összehasonlítja a modelleket, és interaktív HTML riportokat generál.
A rendszer az Open-Meteo ingyenes API-ját használja (nem kell API kulcs), és naponta egyszer fut cron-ból.
Részletes architektúra diagramért lásd az angol verziót (a diagramok nyelv-függetlenek).
# Klónozás és beállítás git clone https://gitlab.com/demogun1/misc_scripts.git cd misc_scripts # Python 3.12 venv létrehozása python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt # Riportok helyi előnézete (nincs deploy, nincs email) ./scripts/weather-forecast/weather-forecast.py --dry-run ./scripts/weather-history/weather-history.py --days 7 --dry-run # Minden futtatása (dry-run) ./run-and-publish.py --dry-run # Minden futtatása + deploy (bőbeszédű mód) ./run-and-publish.py --verbose
misc_scripts/ ├── run-and-publish.py # Vezénylő: generálja a site-ot (retry + email hiba esetén) ├── run.sh # Wrapper: git pull + clean + generálás + rsync ├── .gitlab-ci.yml # CI: lint (ruff) → typecheck (mypy) → test (pytest) → deploy ├── ruff.toml # Lint konfiguráció ├── requirements.txt # Python függőségek ├── tests/ # pytest tesztek (59 db) ├── api/ │ └── php/ # PHP API (tarhely.com hosting-on fut) ├── scripts/ │ ├── weather-forecast/ # Moduláris előrejelzés (fetch→risk→charts→render→summary) │ ├── weather-history/ # Történeti grafikon generátor (19 Chart.js grafikon) │ ├── model-validator/ # Modell pontosság kiértékelő + rangsoroló │ └── headache-analyzer/ # Fejfájás korreláció elemző ├── shared/ │ ├── __init__.py # get_base_styles() — egységes CSS generátor │ ├── config.py # Városok, küszöbértékek, URL-ek │ ├── config_loader.py # Reads config.ini (DB, paths, etc.) │ ├── db.py # MySQL helper (minden DB művelet) │ ├── model_selector.py # Adaptív modellválasztó motor │ ├── i18n.js # Kliens-oldali fordítások (EN/HU) │ └── headaches.py # Fejfájás napló parser ├── data/ # Adat fájlok (JSON fallback) └── public_html/ # Generált webes kimenet
Minden megosztott beállítás a shared/config.py-ban:
# Városok: kulcs → (megjelenített_név, szélesség, hosszúság)
CITIES = {
"inarcs": ("Inárcs", 47.2667, 19.3500),
"budapest": ("Budapest", 47.4979, 19.0402),
"ivancsa": ("Iváncsa", 46.9833, 18.8167),
"gyal": ("Gyál", 47.3833, 19.2167),
}
CITIES dict-hez a shared/config.py-banpublic_html/index.html-bendata/stations.json-be az első evaluate futáskorA rendszer megtanulja melyik modell a legjobb adott helyszín/paraméter/időhorizont kombinációra:
save-forecast.py napi pillanatképeket ment (minden modell)evaluate.py összehasonlítja az előrejelzést a mért adatokkalmodel_selector.py aggregálja a hibákat → kiválasztja a legjobbat| Konstans | Érték | Jelentés |
|---|---|---|
MIN_SAMPLES | 7 | Min. kiértékelések száma a rangsor elfogadásához |
WINDOW_DAYS | 30 | Gördülő ablak a rangsor számításhoz |
SIGNIFICANCE_GAP | 5.0% | Min. előny egy modell preferálásához |
Kliens-oldali EN/HU fordítás a shared/i18n.js segítségével:
data-i18n="kulcs" → kikeresi a TRANSLATIONS dict-bőldata-i18n-en="..." + data-i18n-hu="..." attribútumokclass="lang-en" / class="lang-hu" → show/hideTisztán JavaScript, nincs szükség szerverre. Használt API-k:
| Szolgáltatás | Cél | Limit |
|---|---|---|
| OSRM | Útvonal számítás (távolság, idő, polyline) | Fair use (ingyenes) |
| Open-Meteo | Időjárás előrejelzés pontonként (4 modell) | 10.000/nap |
| Nominatim | Geokódolás + fordított geokódolás | 1 kérés/mp |
| Leaflet + OSM | Térkép megjelenítés | Korlátlan |
# data/headaches.txt # Dátum, Súlyosság (1-3), Megjegyzések 2026-07-15, 2, délutáni kezdet, nyomás csökken 2026-07-22, 3, migrén, viharfront áthalad 2026-08-01, 1, enyhe, párás nap
| Követelmény | Érték |
|---|---|
| Python | 3.11+ (Pi: 3.13, build szerver: 3.12) |
| Függőségek | markdown, pymysql (pip) |
| Adatbázis | MariaDB a tarhely.com-on (config.ini a hitelesítő adatokhoz) |
| SSL javítás (céges) | SSL_CERT_FILE=/etc/pki/tls/certs/ca-bundle.crt |
| Platform | Linux (GIT TS build szerver vagy Raspberry Pi 4) |
| Dokumentum | Leírás |
|---|---|
| 🚀 Üzemeltetési és Release útmutató | Cron, deployment, run.sh, RPi beállítás, hibaelhárítás |
| 🗺️ Egységes Termék Ütemterv | Funkció ütemterv, architektúra döntések, idővonal |