Fichiers
meteo-vercors/maquettes/accueil-carte/scenario.py
T
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

40 lignes
1.9 KiB
Python

# Joue un scénario dans Edge sans affichage : python scenario.py pc|mob URL (étapes dans etapes.json : [[js, attente_s, fichier|null], ...])
import json, subprocess, time, urllib.request, base64, sys, os
import websocket
EDGE = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
mode, url = sys.argv[1], sys.argv[2]
port = 9340 if mode == 'pc' else 9341
proc = subprocess.Popen([EDGE, '--headless=new', '--hide-scrollbars', f'--remote-debugging-port={port}',
'--user-data-dir=' + os.path.abspath('profil-sc-' + mode), 'about:blank'])
try:
for _ in range(50):
try:
page = next(t for t in json.load(urllib.request.urlopen(f'http://127.0.0.1:{port}/json')) if t['type'] == 'page'); break
except Exception:
time.sleep(0.2)
ws = websocket.create_connection(page['webSocketDebuggerUrl'], timeout=60)
n = 0
def cmd(method, **params):
global n
n += 1
ws.send(json.dumps({'id': n, 'method': method, 'params': params}))
while True:
r = json.loads(ws.recv())
if r.get('id') == n:
return r.get('result', r)
if mode == 'pc':
cmd('Emulation.setDeviceMetricsOverride', width=1440, height=860, deviceScaleFactor=1, mobile=False)
else:
cmd('Emulation.setDeviceMetricsOverride', width=390, height=844, deviceScaleFactor=2, mobile=True)
cmd('Page.navigate', url=url); time.sleep(5)
for js, attente, fichier in json.load(open('etapes.json', encoding='utf-8')):
r = cmd('Runtime.evaluate', expression=js, awaitPromise=True, returnByValue=True)
v = r.get('result', {}).get('value')
if v is not None: print(v)
if r.get('exceptionDetails'): print('ERREUR', json.dumps(r['exceptionDetails'])[:400])
time.sleep(attente)
if fichier:
open(fichier, 'wb').write(base64.b64decode(cmd('Page.captureScreenshot')['data']))
finally:
proc.kill()