You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cur.execute("""CREATE TABLE IF NOT EXISTS obdreadings(vehicleid TEXT, unix_timestamp BIGINT, latitude DECIMAL(11,8), longitude DECIMAL(11,8), readings JSON);""")
17
+
print('Database ready to go!')
18
+
19
+
20
+
defput(json_data):
21
+
cur.execute("""INSERT INTO obdreadings(vehicleid, unix_timestamp, latitude, longitude, readings)
Copy file name to clipboardExpand all lines: server.py
+8-26Lines changed: 8 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,13 @@
1
1
importjson
2
2
importos
3
-
importpsycopg2
4
-
importurlparse
5
-
fromflaskimportFlask, request, Response
3
+
fromflaskimportFlask, request, Response, jsonify
6
4
5
+
# Import the database
6
+
importdb
7
7
8
8
app=Flask(__name__)
9
9
10
10
11
-
# Open DB connection
12
-
url=urlparse.urlparse(os.environ["DATABASE_URL"])
13
-
conn=psycopg2.connect(
14
-
database=url.path[1:],
15
-
user=url.username,
16
-
password=url.password,
17
-
host=url.hostname,
18
-
port=url.port
19
-
)
20
-
cur=conn.cursor()
21
-
cur.execute("""CREATE TABLE IF NOT EXISTS obdreadings(vehicleid TEXT, unix_timestamp BIGINT, latitude DECIMAL(11,8), longitude DECIMAL(11,8), readings JSON);""")
22
-
print('Database ready to go!')
23
-
24
-
25
11
@app.route('/', methods=['GET', 'POST', 'PUT'])
26
12
defhome():
27
13
# Handle GET
@@ -37,11 +23,7 @@ def home():
37
23
printstr(json_data)
38
24
39
25
# Store it in the DB
40
-
cur.execute("""INSERT INTO obdreadings(vehicleid, unix_timestamp, latitude, longitude, readings)
0 commit comments