WeatherLink : branchement dans le tick et la publication (etat, attribution) + tests avec reponses simulees
Cette révision appartient à :
1 Parent
b8fd17d0e6
révision
fb235a2c85
3 fichiers modifiés
+220
-2
Aucun fichier ne correspond à votre recherche
@@ -13,13 +13,13 @@ ni l'autre source ni la publication.
|
||||
import datetime as dt
|
||||
import sys
|
||||
|
||||
from . import infoclimat, publier, romma
|
||||
from . import infoclimat, publier, romma, weatherlink
|
||||
from .commun import UTC, Config, Journal, Verrou, lire_json
|
||||
from .stockage import Stockage
|
||||
|
||||
|
||||
def tick(cfg, maintenant=None, fetch_infoclimat=infoclimat.telecharger, fetch_romma=romma.telecharger,
|
||||
appels=True):
|
||||
appels=True, fetch_weatherlink=weatherlink.telecharger, dormir_weatherlink=None):
|
||||
maintenant = maintenant or dt.datetime.now(UTC)
|
||||
var = cfg.base / "var"
|
||||
journal = Journal(var / "collecte.log")
|
||||
@@ -32,6 +32,9 @@ def tick(cfg, maintenant=None, fetch_infoclimat=infoclimat.telecharger, fetch_ro
|
||||
if appels and cfg.romma_actif:
|
||||
resumes["romma"] = _sans_planter(journal, maintenant, "romma",
|
||||
lambda: romma.passer(cfg, stockage, journal, maintenant, fetch_romma))
|
||||
if appels and cfg.weatherlink_actif: # opt-in ; quota et état entièrement séparés
|
||||
resumes["weatherlink"] = _sans_planter(journal, maintenant, "weatherlink", lambda: weatherlink.passer(
|
||||
cfg, stockage, journal, maintenant, fetch_weatherlink, dormir_weatherlink))
|
||||
if appels and cfg.infoclimat_actif:
|
||||
stations = lire_json(cfg.stations, {}).get("infoclimat", {})
|
||||
resumes["infoclimat"] = _sans_planter(journal, maintenant, "infoclimat", lambda: infoclimat.passer(
|
||||
@@ -67,6 +70,14 @@ def main(argv=None):
|
||||
print("%-20s définie (valeur masquée)" % nom)
|
||||
except LookupError:
|
||||
print("%-20s absente" % nom)
|
||||
if cfg.weatherlink_actif:
|
||||
for compte, d in lire_json(cfg.weatherlink_comptes, {}).get("comptes", {}).items():
|
||||
for nom in (d.get("var_cle"), d.get("var_secret")):
|
||||
try:
|
||||
cfg.secret(nom)
|
||||
print("%-28s définie (valeur masquée) [compte %s]" % (nom, compte))
|
||||
except LookupError:
|
||||
print("%-28s absente [compte %s]" % (nom, compte))
|
||||
return 0
|
||||
tick(cfg, appels="--publier" not in argv)
|
||||
return 0
|
||||
|
||||
@@ -21,6 +21,7 @@ ATTRIBUTIONS = {
|
||||
"infoclimat": "Données Infoclimat",
|
||||
"romma": "Source : ROMMA. ROMMA n'est pas responsable des données erronées ou manquantes ni de leur "
|
||||
"interprétation.",
|
||||
"weatherlink": "Station Gastinel (Davis), données WeatherLink de la station",
|
||||
"meteofrance": "Source : Météo-France (Licence Ouverte Etalab 2.0)",
|
||||
}
|
||||
|
||||
@@ -76,6 +77,17 @@ def etat(cfg, maintenant, resumes):
|
||||
"pause_jusqua_utc": iso(p.jusqua()) if p.active(maintenant) else None,
|
||||
"dernier_passage": (resumes.get(src) or {}).get("action"),
|
||||
}
|
||||
if cfg.weatherlink_actif:
|
||||
e = lire_json(cfg.base / "var" / "etat_weatherlink.json", {})
|
||||
succes = [c.get("dernier_succes_utc") for c in e.get("comptes", {}).values() if c.get("dernier_succes_utc")]
|
||||
pauses = [Pause(p, 0) for p in sorted((cfg.base / "var").glob("pause_weatherlink_*.txt"))]
|
||||
actives = [p for p in pauses if p.active(maintenant)]
|
||||
sources["weatherlink"] = {
|
||||
"dernier_succes_utc": iso(lire_utc(max(succes))) if succes else None,
|
||||
"en_pause": bool(actives),
|
||||
"pause_jusqua_utc": iso(max(p.jusqua() for p in actives)) if actives else None,
|
||||
"dernier_passage": ((resumes.get("weatherlink") or {}).get("action")),
|
||||
}
|
||||
return {"mis_a_jour_utc": iso(maintenant), "sources": sources}
|
||||
|
||||
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur