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],