diff --git a/search.py b/search.py new file mode 100755 index 0000000..a20598b --- /dev/null +++ b/search.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +# You can test it with: +# curl --request POST --data name=foobar http://localhost:4000 + +import wsgiref.simple_server as server +import urllib.parse + +import psycopg2 + +PORT = 4000 + +def pack(start_response, status, data): + datae = data.encode() # Always encode to UTF-8 + response_headers = [("Content-type", "text/plain; charset=UTF-8"), + ("Content-Length", str(len(datae)))] + start_response(status, response_headers) + return [datae] + +def application(environ, start_response): + status = "200 OK" + output = "TODO\r\n" + # REQUEST_METHOD + for variable in environ: + print("%s: %s" % (variable, environ[variable])) + try: + body_size = int(environ.get("CONTENT_LENGTH", 0)) + except (ValueError): + body_size = 0 + body = environ["wsgi.input"].read(body_size) + print("") + print("Body \"%s\"" % body.decode()) + query = urllib.parse.parse_qsl(body.decode()) + print("") + print("Query \"%s\"" % query) + return pack(start_response, status, output) + +if __name__ == "__main__": + conn = psycopg2.connect("dbname=lsr") + cursor = conn.cursor() + httpd = server.make_server("", PORT, application) + print("Listening on port %s" % PORT) + httpd.serve_forever() diff --git a/search.xml b/search.xml new file mode 100644 index 0000000..7018157 --- /dev/null +++ b/search.xml @@ -0,0 +1,8 @@ + + +

TODO

+
+

Name:

+

+
+