From 80212a5c03eff362041bc74b165a48fd5bc5d915 Mon Sep 17 00:00:00 2001 From: gnat Date: Sun, 27 Oct 2024 21:57:14 -0700 Subject: [PATCH] add bracelet control api --- src/lib/router.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/lib/router.py b/src/lib/router.py index 60cb878..87b3813 100644 --- a/src/lib/router.py +++ b/src/lib/router.py @@ -11,6 +11,7 @@ from .patchers import patchers from .logger import log import os import traceback +import requests, json @dataclass class Route: @@ -47,6 +48,31 @@ routes = [ parse_file('./index.html').encode('utf-8') ) ), + Route( + lambda request: request.path == '/bracelet.html', + [Method.POST], + lambda request, *_: Response( + ResponseCode.OK, + {'Content-Type': 'text/html'}, + ( + requests.post( + "https://api.pavlok.com/api/v5/stimulus/send", + headers = { # who cares about a pavlok api key + 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6bnVsbCwiaWQiOjMxNDA3NiwiZW1haWwiOiJvZGV0dGVhbWF0bzA3QGdtYWlsLmNvbSIsImlzX2FwcGxpY2F0aW9uIjpmYWxzZSwiZXhwIjoxNzYxMzcyMzIwLCJzdWIiOiJhY2Nlc3MifQ.8dyKDR6opM8dpzXfnXpIO1VJApx880mN6fCrmVUShxc', + 'Content-Type': 'application/json' + }, + data = json.dumps({ + "stimulus": { + "stimulusType": request.body.data['type'], + "stimulusValue": request.body.data['strength'], + "reason": request.body.data['message'], + } + }) + ), + parse_file('./bracelet.html').encode('utf-8') + )[-1] + ) + ), Route( lambda request: os.path.isfile('.' + request.path) and request.path.endswith('.html'), [Method.GET],