main.py 910 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python
  2. """
  3. wifi-with-matrix script.
  4. Bridge between https://code.ffdn.org/FFDN/wifi-with-me & a matrix room
  5. """
  6. from http.server import BaseHTTPRequestHandler, HTTPServer
  7. SERVER_ADDRESS = ('', 4785)
  8. class Forwarder(BaseHTTPRequestHandler):
  9. """
  10. Class given to the server, st. it knows what to do with a request.
  11. This one handles the HTTP request, and forwards it to the matrix room.
  12. """
  13. def do_POST(self):
  14. """
  15. main method, get a json dict from wifi-with-me, send a message to a matrix room
  16. """
  17. self.ret_ok()
  18. def ret_ok(self):
  19. """
  20. return a success status
  21. """
  22. self.send_response(200)
  23. self.send_header('Content-Type', 'application/json')
  24. self.end_headers()
  25. self.wfile.write(b"{'status': 'OK'}")
  26. if __name__ == '__main__':
  27. HTTPServer(SERVER_ADDRESS, Forwarder).serve_forever()