Created
May 28, 2016 11:41
-
-
Save vishvanand/2920518fa9e7b54cbd0edb25eb675483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment