-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiFunctions.py
More file actions
executable file
·27 lines (21 loc) · 909 Bytes
/
ApiFunctions.py
File metadata and controls
executable file
·27 lines (21 loc) · 909 Bytes
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
from Server import *
from flask import make_response, jsonify
# Standard function
def query_db(query, args=(), one=False):
cur = c # c created in _init_.py
# NB if using PostgreSQL, cur.execute returns None, unlike SQLite.
cur.execute(query, args)
rv = [dict((cur.description[idx][0], value)
for idx, value in enumerate(row)) for row in cur.fetchall()]
return (rv[0] if rv else None) if one else rv
def post_db(query, args=(), one=False):
cur = c # c created in _init_.py
# NB if using PostgreSQL, cur.execute returns None, unlike SQLite.
cur.execute(query, args)
rv = [dict((cur.description[idx][0], value)
for idx, value in enumerate(row)) for row in cur.fetchall()]
conn.commit()
return (rv[0] if rv else None) if one else rv
@app.errorhandler(404)
def not_found(error):
return make_response(jsonify({'error': 'Not found'}), 404)