Advertisement
Guest User

API generator

a guest
Apr 11th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. from flask import Flask, jsonify, request
  2. import fdb
  3.  
  4. app = Flask(__name__)
  5.  
  6. con = fdb.connect(dsn='/home/trainee2/Desktop/ice', user='sysdba', password='trainee')
  7. cur = con.cursor()
  8.  
  9.  
  10. @app.route('/', methods=['GET'])
  11. def get_root():
  12.     datum = request.args.get('datum')
  13.     if datum is not None:
  14.         statement = "select * from ICEDATABASE where DATUM = CAST(? AS DATE)"
  15.         cur.execute(statement, [datum])
  16.     else:
  17.         statement = "select * from ICEDATABASE"
  18.         cur.execute(statement)
  19.     people = {'datum': datum, 'attendees': []}
  20.     for (ID, PRENAME, NAME, DATUM, PICTURELINKS, INOROUT) in cur:
  21.         people['attendees'].append({'id': ID, 'prename': PRENAME, 'name': NAME, 'picture': PICTURELINKS, 'inOrOut': INOROUT})
  22.     return jsonify(people)
  23.  
  24. @app.route('/database')
  25. def database():
  26.     statement = "select * from ICEDATABASE"
  27.     people = {'attendees': []}
  28.     cur.execute(statement)
  29.     for (ID, PRENAME, NAME, DATUM, PICTURELINKS, INOROUT) in cur:
  30.         people['attendees'].append({'name': NAME, 'prename': PRENAME, 'id' : ID, 'inorout': INOROUT, 'picture': PICTURELINKS, 'datum': DATUM})
  31.     return jsonify(people)
  32.    
  33.  
  34. @app.route('/lastperson')
  35. def last():
  36.     statement = "select * FROM ICEDATABASE where ID = (select MAX(ID) from ICEDATABASE)"
  37.     cur.execute(statement)
  38.     for (ID, PRENAME, NAME, DATUM, PICTURELINKS, INOROUT) in cur:
  39.         people = ({'name': NAME, 'prename': PRENAME, 'id' : ID, 'inorout': INOROUT, 'picture': PICTURELINKS, 'datum': DATUM})
  40.     return jsonify(people)
  41.  
  42. @app.route('/aantal')
  43. def totaal():
  44.     cur.execute("select (select count(INOROUT) from ICEDATABASE where INOROUT = 0) - (select count(INOROUT) from ICEDATABASE where INOROUT =1) from ICEDATABASE as Verschil")
  45.     for (VERSCHIL) in cur:
  46.         people=({'totaalAantalMensen': { 'verschil' : VERSCHIL}})
  47.     return jsonify(people)
  48.    
  49.    
  50.  
  51. if __name__ == "__main__":
  52.     app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement