-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·62 lines (58 loc) · 1.68 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from flask import Flask, render_template
from flask import request
import psycopg2
import re
import base64
import os, time, http.client
import requests
import urllib.request
import threading
import time
app = Flask(__name__)
@app.route('/')
def runpy():
print("reloading....")
try:
# conn = psycopg2.connect(host="localhost",database="cuetbus", user="postgres", password="")
# """
DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
# """
cur = conn.cursor()
query = "SELECT * FROM padmalatlong"
cur.execute(query)
results = cur.fetchall()
#"""
for res in results:
print(res)
#"""
conn.close()
except Exception as e:
print(e)
return render_template('index.html', results=results)
@app.route('/sendlatlong')
def uploaddata():
print("uploading data....")
lattitude = request.args.get('lat')
longitude = request.args.get('long')
try:
# conn = psycopg2.connect(host="localhost",database="cuetbus", user="postgres", password="")
# """
DATABASE_URL = os.environ['DATABASE_URL']
conn = psycopg2.connect(DATABASE_URL, sslmode='require')
# """
cur = conn.cursor()
query = "UPDATE padmalatlong SET lat=%s, long=%s"
values = (lattitude, longitude)
cur.execute(query, values)
conn.commit()
count = cur.rowcount
print(count)
conn.close()
except Exception as e:
print(e)
return '''{},{}'''.format(lattitude,longitude)
if __name__ == '__main__':
app.debug = True
app.run()
app.run(debug=True)