-
Notifications
You must be signed in to change notification settings - Fork 0
/
crowdcure.py
68 lines (50 loc) · 1.44 KB
/
crowdcure.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
63
64
65
66
67
68
from contextlib import closing
import time
import flask
from flask.ext.iniconfig import INIConfig
import sqlite3
## Setup and config.
app = flask.Flask(__name__)
INIConfig(app)
with app.app_context():
app.config.from_inifile('settings.ini')
## Database stuff.
def connect_db():
return sqlite3.connect(app.config['database']['NAME'])
def init_db():
with closing(connect_db()) as db:
with app.open_resource('schema.sql', mode='r') as f:
db.cursor().executescript(f.read())
db.commit()
## Views.
@app.route('/create-report/', methods=['GET'])
def create_report_get():
return flask.render_template('create_report.html')
@app.route('/create-report/', methods=['POST'])
def create_report_post():
db = connect_db()
db.execute(
'insert into locations (latitude, longitude, timestamp) values (?, ?, ?)',
(
flask.request.form['latitude'],
flask.request.form['longitude'],
int(time.time()),
),
)
db.commit()
db.close()
return 'Added the following to database: {latitude}, {longitude}'.format(
latitude=flask.request.form['latitude'],
longitude=flask.request.form['longitude'],
)
@app.route('/test/', methods=['GET'])
def test_get():
if flask.request.method == 'GET':
return 'Successful GET\n'
@app.route('/test/', methods=['POST'])
def test_post():
if flask.request.method == 'POST':
return 'Successful POST\n'
## Debugging/running support.
if __name__ == '__main__':
app.run()