Begin database part
This commit is contained in:
parent
5da933bb87
commit
5ce2672f97
1 changed files with 15 additions and 0 deletions
15
web-to-db.py
15
web-to-db.py
|
@ -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__':
|
||||
|
|
Loading…
Reference in a new issue