forked from allezViens/ridetheory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
132 lines (117 loc) · 4.4 KB
/
run.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from flask import Flask, request, jsonify, redirect, url_for
from flask.ext.mail import Mail
from flask.ext.sqlalchemy import SQLAlchemy
import os
import json
import sys
import customutilities
app = Flask(__name__, static_folder='client', static_url_path='')
# app.config.update(
# #Comment out for production
# # DEBUG=True,
# #Email Settings
# MAIL_SERVER='smtp.gmail.com',
# MAIL_PORT=465,
# MAIL_USE_SSL=True,
# MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
# MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
# )
# app.config.update(
# #Comment out for production
# DEBUG = True,
# #Email Settings
# SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL",'postgresql://localhost/allezviens'),
# MAIL_SERVER = 'smtp.gmail.com',
# MAIL_PORT = 465,
# MAIL_USE_SSL = True,
# MAIL_DEFAULT_SENDER = '[email protected]',
# MAIL_USERNAME = '[email protected]',
# MAIL_PASSWORD = 'swiftmanatee'
# # MAIL_USERNAME = os.environ.get('MAIL_USERNAME'),
# # MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
# )
db = SQLAlchemy(app)
mail = Mail(app)
from connect import *
from communication import *
@app.route('/')
def root():
return app.send_static_file('index.html')
@app.route('/api/passenger/update', methods=['POST'])
def passengerUpdate():
print 'api passenger update'
if (request.headers['Content-Type'][:16] == 'application/json'):
data = json.loads(request.data)
data = customutilities.detuplify(data)
if updatePassenger(data):
return 'Passenger record updated successfully'
else:
return 'ERROR. Passenger record was not updated.'
@app.route('/api/driver/update', methods=['POST'])
def driverUpdate():
print 'api driver update'
if (request.headers['Content-Type'][:16] == 'application/json'):
data = json.loads(request.data)
data = customutilities.detuplify(data)
print 'after data'
if updateDriver(data):
return 'Driver record updated successfully.'
else:
return 'ERROR. Driver record not updated.'
@app.route('/api/driver', methods=['GET', 'POST'])
def drivers():
if (request.method == 'GET'):
oLat, oLon = float(request.args.get('oLat')), float(request.args.get('oLon'))
dLat, dLon = float(request.args.get('dLat')), float(request.args.get('dLon'))
date = request.args.get('date')
results = findMatchableDrivers(oLat, oLon, dLat, dLon, date)
return jsonify(matches=results)
if (request.method == 'POST'):
if (request.headers['Content-Type'][:16] == 'application/json'):
data = json.loads(request.data)
if (data['type'] == 'create'):
oLat, oLon = float(data['origin'][0]), float(data['origin'][1])
dLat, dLon = float(data['destination'][0]), float(data['destination'][1])
addDriver(data['id'], oLat, oLon, dLat, dLon, data['date'])
# sendValidationEmail(data['id'], 'http://giphy.com/gifs/running-penguin-baby-s73EQWBuDlcas')
return 'Driver added to database'
if (data['type'] == 'pick'):
pickPassenger(data['passengerID'],data['driverID'])
return 'Successful pick'
@app.route('/api/passenger', methods=['GET', 'POST'])
def passengers():
if (request.method == 'GET'):
oLat, oLon = float(request.args.get('oLat')), float(request.args.get('oLon'))
dLat, dLon = float(request.args.get('dLat')), float(request.args.get('dLon'))
date = request.args.get('date')
results = findMatchablePassengers(oLat, oLon, dLat, dLon, date)
return jsonify(matches=results)
if (request.method == 'POST'):
if (request.headers['Content-Type'][:16] == 'application/json'):
data = json.loads(request.data)
if (data['type'] == 'create'):
oLat, oLon = float(data['origin'][0]), float(data['origin'][1])
dLat, dLon = float(data['destination'][0]), float(data['destination'][1])
addPassenger(data['id'], oLat, oLon, dLat, dLon, data['date'])
# sendValidationEmail(data['id'], 'http://giphy.com/gifs/running-penguin-baby-s73EQWBuDlcas')
return 'Passenger added to database'
if (data['type'] == 'pick'):
pickDriver(data['driverID'],data['passengerID'])
return 'Successful pick'
@app.route('/api/trip/<urlID>', methods=['GET'])
def apiTrip(urlID):
if (request.method == 'GET'):
urlType, info = getInfoByUrl(urlID)
if(urlType == 'P'):
return jsonify(passenger=info)
if(urlType == 'D'):
return jsonify(driver=info)
@app.route('/trip/<urlID>')
def trip(urlID):
if(urlExists(urlID)):
return app.send_static_file('index.html')
else:
print 'url does not exist'
return '404 route not found'
if (__name__ == '__main__'):
app.run()