Commit 2cdc7e1a authored by Klaus-Uwe Mitterer's avatar Klaus-Uwe Mitterer

Connect to database, store location => completed endpoint

parent ba4746b7
import cgi
import datetime
import configparser
import pymysql
def getDatabase(path = "config.cfg"):
config = configparser.RawConfigParser()
host = config.get("Database", "host")
user = config.get("Database", "user")
pwd = config.get("Database", "pass")
name = config.get("Database", "name")
conn = pymysql.connect(host, user, pwd, name)
cur = conn.cursor()
return conn, cur
def application(env, re):
if env["REQUEST_METHOD"] == "POST":
args = cgi.parse_qs(env['wsgi.input'].readline().decode(), True)
......@@ -41,5 +56,9 @@ def application(env, re):
timestr = timestamp.strftime('%Y-%m-%d %H:%M:%S')
sql = "INSERT INTO tracker(ts, device, lat, lon, alt) VALUES (\"%s\", \"%s\", %s, %s, %s);" % (timestr, device, str(latitude), str(longitude), str(altitude) or "None")
conn, cur = getDatabase()
sql = "INSERT INTO tracker(ts, device, lat, lon, alt) VALUES (%s, %s, %s, %s, %s);"
cur.execute(sql, (timestr, device, str(latitude), str(longitude), str(altitude) if altitude != None else None))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment