Begin database part

This commit is contained in:
Nico Schottelius 2016-09-16 17:43:00 +02:00
parent 5da933bb87
commit 5ce2672f97
1 changed files with 15 additions and 0 deletions

View File

@ -1,9 +1,12 @@
#!/usr/bin/env python3
import urllib
import psycopg2
from http.server import BaseHTTPRequestHandler, HTTPServer
# HTTPRequestHandler class
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
# not used, just a sample
@ -24,8 +27,20 @@ class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
length = int(self.headers['Content-Length'])
post_data = urllib.parse.parse_qs(self.rfile.read(length).decode('utf-8'))
# Print on stdout
print(post_data)
# And insert into the db
self.insert_xml(post_data)
def insert_xml():
try:
conn = psycopg2.connect("dbname=hackzurich")
except Exception as e:
print("DB Insert failed: %s" % e)
if __name__ == '__main__':