Advertisement
Guest User

Untitled

a guest
May 28th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #!flask/bin/python
  2. from flask import Flask
  3. from flask import abort
  4. from flask import jsonify
  5. app = Flask(__name__)
  6.  
  7. #app.config['SERVER_NAME'] = '192.168.176.139:5000'
  8. app.run(host= '0.0.0.0',port=5000)
  9. @app.route('/')
  10. def index():
  11. return "Hello, World!"
  12.  
  13.  
  14. @app.route('/todo/api/v1.0/traffic/<int:loc_id>', methods=['GET'])
  15. def get_task(loc_id):
  16. f = open("locations.txt")
  17. ret = {}
  18. for line in f:
  19. locs = line.split(" ")
  20. if(locs[0] == str(loc_id)):
  21. ret = {'id':locs[0],'name':locs[1],'count':locs[2][:-1]}
  22.  
  23. if len(ret) == 0:
  24. abort(404)
  25. returnMessage = jsonify({'trafficInfo': ret})
  26. print(ret)
  27. return returnMessage
  28.  
  29.  
  30. @app.route('/todo/api/v1.0/locations', methods=['GET'])
  31. def get_tasks():
  32. f = open("locations.txt")
  33. ret = {}
  34. for line in f:
  35. locs = line.split(" ")
  36. ret[locs[0]] = {'name':locs[1],'count':locs[2][-1]}
  37.  
  38. return jsonify({'ids': ret})
  39.  
  40. @app.route('/signup/', methods=['POST'])
  41. def signup():
  42. name=request.form['yourname']
  43. email=request.form['youremail']
  44. password = request.form['password']
  45. nameofloc = request.form['nameofloc']
  46. numseats = request.form['numseats']
  47.  
  48. f = open("db.txt","w+")
  49. f.write(name+" "+email+" "+password+" "+nameofloc+" "+numseats)
  50. f.close()
  51. return jsonify({"ErrorCode":"Success"})
  52.  
  53. @app.route('/login/', methods=['POST'])
  54. def login():
  55. email=request.form['youremail']
  56. password = request.form['password']
  57. f = open("db.txt","r")
  58.  
  59. for line in f:
  60. fields = line.split(' ')
  61. if(fields[1] == email and fields[2] == password):
  62. val = {"name":name,"nameofloc":nameofloc,"numseats":numseats}
  63. return jsonify({"auth":val})
  64.  
  65. return jsonify({"auth":"Incorrect userid or password"})
  66.  
  67. if __name__ == '__main__':
  68. app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement