From b062c2694ba430381f74de6364de389d067041d0 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 11 Feb 2019 01:00:53 +0100 Subject: [PATCH] decode json from the HTTP request, and post it to the room --- main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.py b/main.py index 112ef5a..f67347d 100755 --- a/main.py +++ b/main.py @@ -10,6 +10,7 @@ Needs the following environment variables: - MMW_BOT_ROOM_ID: the room on which send the notifications """ +import json import os from http.server import BaseHTTPRequestHandler, HTTPServer @@ -44,6 +45,9 @@ class WWMBotForwarder(BaseHTTPRequestHandler): """ main method, get a json dict from wifi-with-me, send a message to a matrix room """ + length = int(self.headers.get('Content-Length')) + data = json.loads(self.rfile.read(length).decode()) + self.server.matrix_room.send_text(f'Got a request on {self.path}: {data}') self.ret_ok() def ret_ok(self):