Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!flask/bin/python
- from flask import Flask
- from flask import abort
- from flask import jsonify
- app = Flask(__name__)
- #app.config['SERVER_NAME'] = '192.168.176.139:5000'
- app.run(host= '0.0.0.0',port=5000)
- @app.route('/')
- def index():
- return "Hello, World!"
- @app.route('/todo/api/v1.0/traffic/<int:loc_id>', methods=['GET'])
- def get_task(loc_id):
- f = open("locations.txt")
- ret = {}
- for line in f:
- locs = line.split(" ")
- if(locs[0] == str(loc_id)):
- ret = {'id':locs[0],'name':locs[1],'count':locs[2][:-1]}
- if len(ret) == 0:
- abort(404)
- returnMessage = jsonify({'trafficInfo': ret})
- print(ret)
- return returnMessage
- @app.route('/todo/api/v1.0/locations', methods=['GET'])
- def get_tasks():
- f = open("locations.txt")
- ret = {}
- for line in f:
- locs = line.split(" ")
- ret[locs[0]] = {'name':locs[1],'count':locs[2][-1]}
- return jsonify({'ids': ret})
- @app.route('/signup/', methods=['POST'])
- def signup():
- name=request.form['yourname']
- email=request.form['youremail']
- password = request.form['password']
- nameofloc = request.form['nameofloc']
- numseats = request.form['numseats']
- f = open("db.txt","w+")
- f.write(name+" "+email+" "+password+" "+nameofloc+" "+numseats)
- f.close()
- return jsonify({"ErrorCode":"Success"})
- @app.route('/login/', methods=['POST'])
- def login():
- email=request.form['youremail']
- password = request.form['password']
- f = open("db.txt","r")
- for line in f:
- fields = line.split(' ')
- if(fields[1] == email and fields[2] == password):
- val = {"name":name,"nameofloc":nameofloc,"numseats":numseats}
- return jsonify({"auth":val})
- return jsonify({"auth":"Incorrect userid or password"})
- if __name__ == '__main__':
- app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement