- outputs/platform, outputs/prospect : scripts de construction des decks commerciaux + captures sources et .pptx generes. - outputs/mnaha : seed complet de l'instance de demo luxembourgeoise (scripts par etape, contenus, images generees), le deck en version marque blanche et en version brandee, le PDF de presentation. - outputs/Wireframes : maquettes app mobile, app web et manager. - interview clients : notes de l'entretien Fourneau St Michel. state.json et les __pycache__ sont ignores : le premier porte les cles d'API de l'instance seedee, les scripts le regenerent.
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Client minimal pour l'API locale de manager-service.
|
|
|
|
Le certificat de dev n'est pas vérifié : on tape sur localhost, pas sur la prod.
|
|
"""
|
|
|
|
import json
|
|
import urllib3
|
|
import requests
|
|
|
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
BASE = "https://localhost:5001"
|
|
EMAIL = "test@email.be"
|
|
PASSWORD = "kljqsdkljqsd"
|
|
|
|
LANGS = ["FR", "DE", "EN", "NL"]
|
|
|
|
|
|
class Api:
|
|
def __init__(self):
|
|
self.s = requests.Session()
|
|
self.s.verify = False
|
|
r = self.s.post(f"{BASE}/api/Authentication/Authenticate",
|
|
json={"email": EMAIL, "password": PASSWORD}, timeout=30)
|
|
r.raise_for_status()
|
|
self.token = r.json()["access_token"]
|
|
self.s.headers.update({"Authorization": f"Bearer {self.token}",
|
|
"Content-Type": "application/json"})
|
|
|
|
def _call(self, method, path, timeout=600, **kw):
|
|
# Généreux à dessein : un PUT sur une section déclenche sa ré-indexation
|
|
# pour l'assistant, donc un embedding par morceau et par langue.
|
|
r = self.s.request(method, f"{BASE}{path}", timeout=timeout, **kw)
|
|
if not r.ok:
|
|
raise RuntimeError(f"{method} {path} -> {r.status_code}\n{r.text[:600]}")
|
|
if not r.content:
|
|
return None
|
|
try:
|
|
return r.json()
|
|
except json.JSONDecodeError:
|
|
return r.text
|
|
|
|
def get(self, path, **kw):
|
|
return self._call("GET", path, **kw)
|
|
|
|
def post(self, path, body=None, **kw):
|
|
return self._call("POST", path, json=body, **kw)
|
|
|
|
def put(self, path, body=None, **kw):
|
|
return self._call("PUT", path, json=body, **kw)
|
|
|
|
def delete(self, path, **kw):
|
|
return self._call("DELETE", path, **kw)
|
|
|
|
|
|
def tr(**by_lang):
|
|
"""{'FR': 'Bonjour'} -> [{'language': 'FR', 'value': 'Bonjour'}], toutes langues.
|
|
|
|
Une langue absente reprend le français : mieux vaut un contenu non traduit
|
|
qu'un champ vide qui casserait l'affichage sur la borne.
|
|
"""
|
|
fallback = by_lang.get("FR") or next(iter(by_lang.values()), "")
|
|
return [{"language": lang, "value": by_lang.get(lang, fallback)} for lang in LANGS]
|