Fichiers
Théo GastineletClaude Sonnet 5.5 ff42faca16 vercors.me : collecte Météo-France / Infoclimat / VP2, archive SQLite, accueil en carte, forum (squelette)
- collecte : collecter_meteofrance, extraire_infoclimat, extraire_vp2, archiver_historique, importer_opendata ; WeatherLink allégé (alleger)
- tests : meteofrance, infoclimat, vp2, archive, opendata (tous verts)
- maquettes/accueil-carte : sources de la maquette (générateurs de tuiles, page, À propos, CGU, confidentialité)
- forum : noyau local (rôles, droits, SQLite, serveur de test, 18 tests)
- deploy : Caddyfile.vercors.me.v2 (non appliqué)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-04 02:24:57 +01:00

139 lignes
12 KiB
Python

# UX : polices locales, meta, recherche, filtre vent/pluie, liste cliquable, liens partageables, donnée vieillissante,
# accessibilité, footer avec accroche, page À propos.
import re
ACCROCHE = "Des stations de chez nous, des chiffres d'ici."
fontface = open('polices/fontface.css', encoding='utf-8').read()
p = 'modele.html'
s = open(p, encoding='utf-8').read()
def rep(old, new, count=1):
global s
assert old in s, old[:80]
s = s.replace(old, new, count)
# 1. polices locales, meta, icône, aucun serveur tiers
rep("""<title>Météo Vercors — maquette d'accueil</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Bitter:ital,wght@0,500;0,600;0,700;1,500&family=Outfit:wght@400;500;600&display=swap" rel="stylesheet">
<style>""", """<title>Météo Vercors : la température du Vercors, station par station</title>
<meta name="theme-color" content="#f5f3ee">
<meta name="description" content="Les températures en direct de 21 stations du Vercors, de Villard-de-Lans à Die : courbes sur 7 jours, vent et pluie.">
<meta property="og:title" content="Météo Vercors"><meta property="og:description" content="Le Vercors en direct, station par station.">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%231f4d3a'/%3E%3Cpath d='M3 24 12 9l5 8 3-4 9 11z' fill='%23f5f3ee'/%3E%3C/svg%3E">
<link rel="preload" href="polices/outfit-normal.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="polices/bitter-normal.woff2" as="font" type="font/woff2" crossorigin>
<style>
""" + fontface + "\n")
rep("<main class=\"carte ouverture\" id=\"carte\">", "<main class=\"carte ouverture\" id=\"carte\" aria-label=\"Carte des stations météo du Vercors\">")
# 2. cartouche : recherche + filtre
rep(' <p class="reseau" id="reseau"></p>', """ <p class="reseau" id="reseau"></p>
<div class="outils" id="outils">
<div class="rech"><input type="search" id="rech" placeholder="Une station, un village…" autocomplete="off" aria-label="Chercher une station ou un village"><ul id="rech-res" hidden></ul></div>
<button type="button" id="filtre" aria-pressed="false" title="Montrer les stations qui mesurent le vent ou la pluie">Vent · pluie</button>
</div>""")
rep("#retour{display:none;", """.outils{display:flex;gap:8px;margin-top:12px}
.rech{position:relative;flex:1;min-width:0}
#rech{width:100%;font:inherit;font-size:13.5px;color:var(--roche);background:#fff;border:1px solid var(--roche);border-radius:0;padding:7px 9px;-webkit-appearance:none;appearance:none}
#rech::placeholder{color:#8a8f88}
#rech-res{position:absolute;left:0;right:0;top:100%;z-index:8;margin:2px 0 0;padding:0;list-style:none;background:#fff;border:1px solid var(--roche);max-height:260px;overflow:auto}
#rech-res li{padding:7px 9px;font-size:13.5px;cursor:pointer;border-top:1px solid var(--pierre)}
#rech-res li:first-child{border-top:0}
#rech-res li.on,#rech-res li:hover{background:#eef2ea}
#rech-res small{color:var(--gris);margin-left:6px}
#filtre{font:inherit;font-size:11.5px;font-weight:600;letter-spacing:.08em;text-transform:uppercase;color:var(--sapin);background:#fff;border:1px solid var(--sapin);border-radius:0;padding:7px 9px;cursor:pointer;white-space:nowrap}
#filtre[aria-pressed=true]{background:var(--sapin);color:#fff}
.carte.filtre .puce > button.sans{opacity:.2}
.puce .ics{display:none;margin-left:6px;vertical-align:1px}
.carte.filtre .puce .ics{display:inline}
a:focus-visible,button:focus-visible,input:focus-visible{outline:2px solid var(--sapin);outline-offset:2px}
.vieux{color:var(--chaud)!important}
#retour{display:none;""")
rep(" .cartouche.replie #retour{display:none}", " .cartouche.replie #retour,.cartouche.replie .outils{display:none}")
# 3. puces : icônes de capteurs (affichées avec le filtre) et état « sans capteur »
rep(" const hb = `<span class=\"val\" style=\"color:${couleur(r.t)}\">${fmt(r.t)}</span>${autres ? `<span class=\"n\">+${autres}</span>` : ''}<span class=\"nom\">${p.titre}</span>`;",
" const cap = st.some(x => SEM[x.id] && SEM[x.id].pluie), vent = st.some(x => SEM[x.id] && SEM[x.id].vent);\n"
" p.b.classList.toggle('sans', !cap && !vent);\n"
" const hb = `<span class=\"val\" style=\"color:${couleur(r.t)}\">${fmt(r.t)}</span>${autres ? `<span class=\"n\">+${autres}</span>` : ''}<span class=\"nom\">${p.titre}<span class=\"ics\">${cap ? IC_GOUTTE : ''}${vent ? IC_EOLIENNE : ''}</span></span>`;")
# 4. liste cliquable vers le plein écran
rep(""" return `<a class="case${s.exemple ? ' ex' : ''}" href="#"><small>""", """ return `<button type="button" class="case${s.exemple ? ' ex' : ''}" data-id="${id}"><small>""")
rep("""<b style="color:${couleur(s.t)}">${fmt(s.t)}</b></a>`;
}).join('')}</div>`).join('');""", """<b style="color:${couleur(s.t)}">${fmt(s.t)}</b></button>`;
}).join('')}</div>`).join('');""")
rep(".case{border-right:1px solid var(--roche);border-bottom:1px solid var(--roche);padding:12px 14px;text-decoration:none;background:#faf9f5}",
".case{font:inherit;color:inherit;text-align:left;cursor:pointer;border:0;border-radius:0;border-right:1px solid var(--roche);border-bottom:1px solid var(--roche);padding:12px 14px;text-decoration:none;background:#faf9f5}")
rep("listeStations();\n", "listeStations();\ndocument.getElementById('secteurs').addEventListener('click', ev => {\n const c = ev.target.closest('.case'); if (c && STATIONS[c.dataset.id]) ouvrirPlein([c.dataset.id], c.dataset.id);\n});\n")
# 5. adresse partageable : #station=<id> ouvre le plein écran
rep(" if (!deja) { history.pushState({plein: 1}, ''); requestAnimationFrame(() => plein.classList.add('vu')); }",
" if (!deja) { history.pushState({plein: 1}, '', '#station=' + id); requestAnimationFrame(() => plein.classList.add('vu')); }\n else history.replaceState({plein: 1}, '', '#station=' + id);")
rep("function masquerPlein(){", "function masquerPlein(){\n if (location.hash.startsWith('#station=')) history.replaceState(null, '', location.pathname + location.search);")
rep("// ouverture : les courbes se tracent", "// lien direct vers une station : #station=autrans\nfunction ouvrirDepuisAdresse(){\n const m = location.hash.match(/^#station=([\\w-]+)/);\n if (m && STATIONS[m[1]] && plein.hidden) ouvrirPlein([m[1]], m[1]);\n}\naddEventListener('hashchange', ouvrirDepuisAdresse);\n\n// ouverture : les courbes se tracent")
rep("Promise.race([chargerDonnees(), new Promise(r => setTimeout(r, 1500))]).then(ouverture);",
"Promise.race([chargerDonnees(), new Promise(r => setTimeout(r, 1500))]).then(() => { ouverture(); ouvrirDepuisAdresse(); });")
# 6. donnée vieillissante : pancarte en couleur chaude au-delà de 45 minutes
rep(" document.getElementById('direct').textContent = `Relevés de ${heureReleve} · ${min < 1 ? 'à l’instant' : `il y a ${min} min`}`;",
" const d = document.getElementById('direct');\n d.textContent = `Relevés de ${heureReleve} · ${min < 1 ? 'à l’instant' : min < 120 ? `il y a ${min} min` : `il y a ${Math.round(min / 60)} h`}`;\n d.classList.toggle('vieux', min > 45);")
# 7. recherche et filtre
rep("// téléphone : le cartouche se replie", """// recherche : stations d'abord, puis villages et sommets de la carte
const RECH = [];
Object.keys(STATIONS).forEach(id => RECH.push({n: STATIONS[id].nom, id, lon: STATIONS[id].lon, lat: STATIONS[id].lat, t: 'station'}));
ETIQ.filter(e => ['village', 'ville', 'pic'].includes(e.t)).forEach(e => RECH.push({n: e.n, lon: e.lon, lat: e.lat, t: e.t === 'pic' ? 'sommet' : 'commune'}));
const norm = x => x.normalize('NFD').replace(/[\\u0300-\\u036f]/g, '').toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
const rech = document.getElementById('rech'), resultats = document.getElementById('rech-res');
let choixRech = -1;
function listerRecherche(){
const q = norm(rech.value);
const l = q ? RECH.filter(r => norm(r.n).includes(q)).sort((a, b) => (a.t === 'station' ? 0 : 1) - (b.t === 'station' ? 0 : 1)).slice(0, 7) : [];
resultats.innerHTML = l.map((r, i) => `<li data-i="${RECH.indexOf(r)}" class="${i === choixRech ? 'on' : ''}">${r.n}<small>${r.t}</small></li>`).join('');
resultats.hidden = !l.length;
return l;
}
function allerA(r){
resultats.hidden = true; rech.blur(); rech.value = '';
fermer();
const b = r.id ? boite([r.id]) : [r.lon - 0.05, r.lat + 0.04, r.lon + 0.05, r.lat - 0.04];
zoomer(b);
if (r.id) setTimeout(() => { const p = puces.find(q => q.ids.includes(r.id) && !q.m.classList.contains('cache')); if (p) ouvrir(p); }, 650);
}
rech.addEventListener('input', () => { choixRech = -1; listerRecherche(); });
rech.addEventListener('keydown', ev => {
const l = listerRecherche();
if (ev.key === 'ArrowDown') { choixRech = Math.min(l.length - 1, choixRech + 1); listerRecherche(); ev.preventDefault(); }
else if (ev.key === 'ArrowUp') { choixRech = Math.max(0, choixRech - 1); listerRecherche(); ev.preventDefault(); }
else if (ev.key === 'Enter' && l.length) { allerA(l[Math.max(0, choixRech)]); }
else if (ev.key === 'Escape') { resultats.hidden = true; }
});
resultats.addEventListener('mousedown', ev => { const li = ev.target.closest('li'); if (li) { ev.preventDefault(); allerA(RECH[+li.dataset.i]); } });
rech.addEventListener('blur', () => setTimeout(() => { resultats.hidden = true; }, 120));
const filtre = document.getElementById('filtre');
filtre.addEventListener('click', () => { const on = filtre.getAttribute('aria-pressed') !== 'true'; filtre.setAttribute('aria-pressed', on); carte.classList.toggle('filtre', on); relancer(); });
['rech', 'filtre'].forEach(i => document.getElementById(i).addEventListener('click', ev => ev.stopPropagation()));
// téléphone : le cartouche se replie""")
# la barre de recherche ne doit pas déclencher le repli au toucher
rep(" if (ev.target.closest('a, button') || carte.clientWidth >= 720) return;", " if (ev.target.closest('a, button, input, .rech') || carte.clientWidth >= 720) return;")
# 8. footer avec accroche, noscript
rep("<footer>Météo Vercors · données : Météo-France (Licence Ouverte), Infoclimat (CC BY ou CC BY-NC selon la station), station Gastinel · fond de carte IGN, licence ouverte</footer>",
"""<footer class="pied">
<p class="accroche">%s</p>
<p>Données : Météo-France (Licence Ouverte), Infoclimat (CC BY ou CC BY-NC selon la station), WeatherLink, station Gastinel. Fond de carte : IGN, licence ouverte.</p>
<p><a href="a-propos.html">À propos</a> · <a href="a-propos.html#sources">Sources et licences</a> · <a href="a-propos.html#mentions">Mentions légales</a> · © Théo Gastinel</p>
</footer>
<noscript><p style="max-width:640px;margin:0 auto;padding:16px;font-family:system-ui">Météo Vercors a besoin de JavaScript pour afficher la carte et les relevés en direct. Les sources et les mentions légales sont sur la page <a href="a-propos.html">À propos</a>.</p></noscript>""" % ACCROCHE)
rep("footer{max-width:1080px;margin:0 auto;padding:18px 28px 40px;font-size:12px;color:var(--gris);border-top:1px solid var(--pierre)}",
".pied{max-width:1080px;margin:0 auto;padding:22px 28px 44px;font-size:12.5px;color:var(--gris);border-top:1px solid var(--pierre)}\n.pied p{margin:6px 0}\n.pied .accroche{font-family:var(--titre);font-style:italic;font-size:17px;color:var(--sapin)}\n.pied a{color:var(--sapin)}")
rep(" footer{padding:16px}", " .pied{padding:18px 16px 36px}")
open(p, 'w', encoding='utf-8').write(s)
a = open('a-propos.html', encoding='utf-8').read().replace('/*POLICES*/', fontface).replace('/*ACCROCHE*/', ACCROCHE)
open('a-propos-build.html', 'w', encoding='utf-8').write(a)
print('ok')