-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
699 lines (588 loc) · 24 KB
/
app.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
# app.py
import asyncio
from math import atan2, cos, radians, sin, sqrt
import math
import random
from flask import Flask, jsonify, request
from flask_restful import Resource, Api
from flask_swagger_ui import get_swaggerui_blueprint
import googlemaps
from datetime import datetime
import polyline
from firebase_admin import firestore, initialize_app, credentials, exceptions
import requests
from config import API_KEY
from flask_cors import CORS, cross_origin
from geopy.distance import geodesic
from google.cloud.firestore_v1 import SERVER_TIMESTAMP
# from apscheduler.schedulers.background import BackgroundScheduler
gmaps = googlemaps.Client(key=API_KEY)
app = Flask(__name__)
CORS(app)
api = Api(app)
# Configure Swagger UI
SWAGGER_URL = '/swagger'
API_URL = "/static/swagger.json"
swaggerui_blueprint = get_swaggerui_blueprint(
SWAGGER_URL,
API_URL,
config={
'app_name': "CoDrive"
}
)
app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)
cred = credentials.Certificate("firebase-admin.json")
initialize_app(cred)
db = firestore.client()
userRef = db.collection("Users")
vehicleRef = db.collection("Vehicles")
reviewRef = db.collection("Reviews")
rideRef = db.collection("Rides")
# scheduler = BackgroundScheduler()
def printHello():
print("Hello")
# scheduler.add_job(printHello, 'interval', seconds=10)
# scheduler.start()
@app.route('/hello')
def hello():
return {"members":["member1","member2","member5"]}
# api.add_resource(hello, '/hello')
def get_vehicle(vehicle_id):
docRef = vehicleRef.document(vehicle_id)
doc = docRef.get()
if doc.exists:
vehicle = doc.to_dict()
vehicle["Id"] = vehicle_id
return vehicle
else:
return None
def get_reviewer(user_id):
docRef = userRef.document(user_id)
doc = docRef.get()
if doc.exists:
data = doc.to_dict()
return {
"Name": f"{data['FirstName']} {data['LastName']}",
"ProfileUrl": data['ProfileUrl'],
"Id": user_id
}
else:
return None
def get_review(review_id):
docRef = reviewRef.document(review_id)
doc = docRef.get()
if doc.exists:
data = doc.to_dict()
data["Id"] = review_id
data["Reviewer"] = get_reviewer(data["Reviewer"].get().id)
return data
else:
return None
def get_driver(user_id):
docRef = userRef.document(user_id)
doc = docRef.get()
if doc.exists:
data = doc.to_dict()
return {
"Name": f"{data['FirstName']} {data['LastName']}",
"ProfileUrl": data['ProfileUrl'],
"Id": user_id,
"PhoneNumber": data["PhoneNumber"],
"Gender": data["Gender"]
}
else:
return None
def get_corider(user_id):
docRef = userRef.document(user_id)
doc = docRef.get()
if doc.exists:
data = doc.to_dict()
return {
"Name": f"{data['FirstName']} {data['LastName']}",
"ProfileUrl": data['ProfileUrl'],
"Id": user_id,
"Gender": data["Gender"],
"PhoneNumber": data["PhoneNumber"]
}
else:
return None
def get_ride(ride_id):
docRef = rideRef.document(ride_id)
doc = docRef.get()
if doc.exists:
data = doc.to_dict()
data["Id"] = ride_id
if "Driver" in data:
data["Driver"] = get_driver(data["Driver"].get().id)
if "Vehicle" in data:
data["Vehicle"] = get_vehicle(data["Vehicle"].get().id)
coRidersRef = docRef.collection("CoRiders")
co_riders = coRidersRef.get()
co_riders_data = []
for co_rider in co_riders:
co_rider_data = co_rider.to_dict()
co_rider_data["Id"] = co_rider.id
if co_rider_data["CoRider"]:
co_rider_data["CoRider"] = get_corider(co_rider_data["CoRider"].get().id)
co_riders_data.append(co_rider_data)
data["CoRiders"] = co_riders_data
return data
else:
return None
def get_corider(corider_id):
docRef = userRef.document(corider_id)
doc = docRef.get()
if doc.exists:
data = doc.to_dict()
return {
"Name": f"{data['FirstName']} {data['LastName']}",
"ProfileUrl": data['ProfileUrl'],
"Id": corider_id,
"PhoneNumber": data['PhoneNumber'],
"Gender": data["Gender"],
}
else:
return None
def calculate_distance(lat1, lon1, lat2, lon2):
# Radius of the Earth in kilometers
R = 6371.0
# Convert latitude and longitude from degrees to radians
lat1_rad = radians(lat1)
lon1_rad = radians(lon1)
lat2_rad = radians(lat2)
lon2_rad = radians(lon2)
# Difference in latitude and longitude
dlat = lat2_rad - lat1_rad
dlon = lon2_rad - lon1_rad
# Haversine formula
a = sin(dlat / 2)**2 + cos(lat1_rad) * cos(lat2_rad) * sin(dlon / 2)**2
c = 2 * atan2(sqrt(a), sqrt(1 - a))
distance = R * c
return distance
@app.route('/get_ride', methods=['GET'])
def get_ride_details():
try:
rideId = request.args.get('rideId')
return get_ride(rideId), 200
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/get_user', methods=['GET'])
def get_user():
try:
docRef = userRef.document(request.args.get('userId'))
doc = docRef.get()
if doc.exists:
user_data = doc.to_dict()
user_data["Id"] = doc.id
if "Reviews" in user_data:
user_data["Reviews"] = [get_review(ref.get().id) for ref in user_data["Reviews"]]
if "Vehicles" in user_data:
user_data["Vehicles"] = [get_vehicle(ref.get().id) for ref in user_data["Vehicles"]]
if "History"in user_data:
del user_data["History"]
return jsonify(user_data), 200
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/get_history', methods=['GET'])
def get_history():
try:
docRef = userRef.document(request.args.get('userId'))
doc = docRef.get()
if doc.exists:
user_data = doc.to_dict()
if "History" in user_data:
user_data["History"] = [get_ride(ref.get().id) for ref in user_data["History"]]
history_data = user_data["History"]
return jsonify(history_data), 200
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/get_directions')
def get_directions():
try:
# Get source and destination
source_lat = float(request.args.get('s1'))
source_lng = float(request.args.get('s2'))
destination_lat = float(request.args.get('d1'))
destination_lng = float(request.args.get('d2'))
source_str = f"{source_lat},{source_lng}"
destination_str = f"{destination_lat},{destination_lng}"
print("Hello", source_str, destination_str)
# Request directions from Google Maps API
directions_result = gmaps.directions(
source_str,
destination_str,
mode="driving", # You can change the mode based on your requirements
departure_time=datetime.now(),
)
# Extract relevant information from the directions result
route = directions_result[0]['legs'][0]
steps = route['steps']
total_distance = route['distance']['text']
total_duration = route['duration']['text']
# Use arrival_time if available, otherwise, use duration_in_traffic
eta = route['arrival_time']['text'] if 'arrival_time' in route else route['duration_in_traffic']['text']
# Extract polyline coordinates
encoded_polyline = directions_result[0]['overview_polyline']['points']
decoded_polyline = polyline.decode(encoded_polyline)
# Additional information
total_steps = len(steps)
response_data = {
'status': 'success',
'total_distance': total_distance,
'total_duration': total_duration,
'eta': eta,
'polyline_coordinates': decoded_polyline,
'total_steps': total_steps,
'steps': [{
'instruction': step['html_instructions'],
'distance': step['distance']['text'],
'duration': step['duration']['text'],
'start_location': step['start_location'],
'end_location': step['end_location'],
} for step in steps],
}
return jsonify(response_data)
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/add_vehicle', methods=['POST'])
def add_vehicle():
try:
data = request.json
userId = data.get('userId')
vehicle_data = {
"FuelType": data.get('fuelType'),
"SeatingCapcity": data.get('seatingCapacity'),
"VehicleName": data.get('vehicleName'),
"VehicleNumber": data.get('vehicleNumber')
}
doc_ref = vehicleRef.document()
doc_ref.set(vehicle_data)
doc_id = doc_ref.id
user_doc = userRef.document(userId)
user_doc.update({"Vehicles": firestore.ArrayUnion([doc_ref])})
return jsonify({"message": "Vehicle added successfully", "document_id": doc_id, "data": vehicle_data}), 200
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/get_places', methods=['GET'])
def get_places():
query = request.args.get('query')
src_lat = float(request.args.get('src_lat'))
src_lng = float(request.args.get('src_lng'))
location = f'{src_lat}, {src_lng}'
radius = 50000
url = f'https://maps.googleapis.com/maps/api/place/textsearch/json?query={query}&location={location}&radius={radius}&key={API_KEY}'
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for HTTP errors
data = response.json()
places = data.get('results', [])
if not places:
return jsonify({'error': 'No places found.'}), 404
results = []
for place in places:
place_lat = place['geometry']['location']['lat']
place_lon = place['geometry']['location']['lng']
distance = calculate_distance(src_lat, src_lng, place_lat, place_lon)
place['distance'] = distance
results.append(place)
sorted_places = sorted(places, key=lambda x: x["distance"])
if(len(sorted_places) > 0):
return jsonify({'places': sorted_places}), 200
else:
return jsonify({'places': []}), 201
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/get_is_on_ride', methods=['GET'])
def get_is_on_ride():
userId = request.args.get('userId')
userDocRef = userRef.document(userId)
userDoc = userDocRef.get()
try:
if(userDoc.exists):
data = userDoc.to_dict()
if "IsOnRide" in data:
return data["IsOnRide"], 200
else:
return [False, ""], 200
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/start_ride', methods=['GET'])
def start_ride():
try:
userId = request.args.get('userId')
vehicleId = request.args.get('vehicleId')
distance = request.args.get('totalDistance')
s_lat = float(request.args.get('s_lat'))
s_lng = float(request.args.get('s_lng'))
s_str = request.args.get('s_str')
d_lat = float(request.args.get('d_lat'))
d_lng = float(request.args.get('d_lng'))
d_str = request.args.get('d_str')
seatingCapacity = int(request.args.get('seatingCapacity'))
isNow = request.args.get('isNow')
startTime = 0
if(isNow):
startTime = SERVER_TIMESTAMP
else:
startTime = request.args.get('startTime')
source = [s_lat, s_lng, s_str]
destination = [d_lat, d_lng, d_str]
driver_ref = userRef.document(userId)
ride_data = {
"Source": source,
"Destination": destination,
"Status": "Started",
"StartTime": startTime,
"Driver": driver_ref,
"JoinedRiders": 0,
"SeatingCapacity": seatingCapacity,
# "TotalDistance": distance,
"Vehicle": vehicleRef.document(vehicleId),
"Updated": 0,
}
doc_ref = rideRef.document()
doc_ref.set(ride_data)
doc_id = doc_ref.id
user_doc = userRef.document(userId)
user_doc.update({"History": firestore.ArrayUnion([doc_ref]), "IsOnRide": [True, doc_id]})
return jsonify({"message": "Ride started successfully", "document_id": doc_id}), 200
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/join_ride', methods=['GET'])
def join_ride():
try:
userId = request.args.get('userId')
rideId = request.args.get('rideId')
amount = float(request.args.get('amount'))
# Pickup Latitude, Longitude & String
p_lat = float(request.args.get('p_lat'))
p_lng = float(request.args.get('p_lng'))
p_str = request.args.get('p_str')
# Drop Latitude, Longitude & String
d_lat = float(request.args.get('d_lat'))
d_lng = float(request.args.get('d_lng'))
d_str = request.args.get('d_str')
pickup = [p_lat, p_lng, p_str]
drop = [d_lat, d_lng, d_str]
corider_ref = userRef.document(userId)
ride_doc_ref = rideRef.document(rideId)
ride_doc = rideRef.document(rideId).get()
if(ride_doc.exists):
data = ride_doc.to_dict()
if(data["JoinedRiders"] == data["SeatingCapacity"]):
return jsonify({"error": "Ride is full, please try joining another ride."}), 500
doc_ref = rideRef.document(rideId).collection("CoRiders").document()
ride_data = {
"Pickup": pickup,
"Drop": drop,
"PickupTime": SERVER_TIMESTAMP,
"DropTime": SERVER_TIMESTAMP,
"Distance": 1,
"CoRider": corider_ref,
"Amount": amount,
"Status": "Requested",
"CompletionCode": random.randint(10000, 99999),
}
doc_ref.set(ride_data)
doc_id = doc_ref.id
user_doc = userRef.document(userId)
user_doc.update({"History": firestore.ArrayUnion([doc_ref])})
ride_doc_ref.update({"Updated": ride_doc.to_dict()["Updated"] + 1})
return jsonify({"message": "Ride joined successfully", "document_id": doc_id}), 200
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/accept_join_request', methods=['GET'])
def accept_join_request():
rideId = request.args.get('rideId')
coriderId = request.args.get('coriderId')
rideDocRef = rideRef.document(rideId)
rideDoc = rideDocRef.get()
coriders = rideDocRef.collection("CoRiders")
coriderRef = coriders.document(coriderId)
corider = coriderRef.get()
try:
if rideDoc.to_dict()["JoinedRiders"] < rideDoc.to_dict()["SeatingCapacity"]:
if corider.exists:
data = corider.to_dict()
data["CoRider"] = get_corider(data["CoRider"].get().id)
coRiderMainDocRef = userRef.document(data["CoRider"]["Id"])
corider_main_data = coRiderMainDocRef.get().to_dict()
if "IsOnRide" in corider_main_data:
if(corider_main_data["IsOnRide"][0]):
return jsonify({"message": "User has already joined another ride."}), 201
coriderRef.update({"Status": "Joined"})
ride_data = rideDoc.to_dict()
rideDocRef.update({"Updated": ride_data["Updated"] + 1})
coRiderMainDocRef.update({"History": firestore.ArrayUnion([rideDocRef]), "IsOnRide": [True, rideId]})
return jsonify({"message": "Joining request has been accepted."}), 200
else:
return jsonify({"err": "Corider doesn't exist"}), 500
else:
return jsonify({"err": "Ride is full"}), 500
except requests.exceptions.RequestException as e:
return jsonify({'error': str(e)}), 500
@app.route('/reject_join_request', methods=['GET'])
def reject_join_request():
rideId = request.args.get('rideId')
coriderId = request.args.get('coriderId')
rideDocRef = rideRef.document(rideId)
rideDoc = rideDocRef.get()
coriders = rideDocRef.collection("CoRiders")
coriderRef = coriders.document(coriderId)
corider = coriderRef.get()
if corider.exists:
data = corider.to_dict()
data["CoRider"] = get_corider(data["CoRider"].get().id)
coRiderMainDocRef = userRef.document(data["CoRider"]["Id"])
coriderRef.update({"Status": "Rejected"})
ride_data = rideDoc.to_dict()
rideDocRef.update({"Updated": ride_data["Updated"] + 1})
coRiderMainDocRef.update({"History": firestore.ArrayUnion([rideDocRef]), "IsOnRide": [False, rideId]})
return jsonify({"message": "Joining request has been accepted."}), 200
else:
return jsonify({"err": "corider doesn't exist"}), 500
@app.route('/complete_corider_ride', methods=['GET'])
def complete_corider_ride():
rideId = request.args.get('rideId')
coriderId = request.args.get('coriderId')
completionCode = int(request.args.get('completionCode'))
rideDoc = rideRef.document(rideId)
coriders = rideDoc.collection("CoRiders")
coriderRef = coriders.document(coriderId)
corider = coriderRef.get()
rideDocGet = rideDoc.get()
if corider.exists:
data = corider.to_dict()
if data["CompletionCode"] == completionCode and data["Status"] == "Joined":
if rideDocGet.exists:
ride_data = rideDocGet.to_dict()
coRiderMainDocRef = userRef.document(data["CoRider"].id)
balance = coRiderMainDocRef.get().to_dict()["Balance"]
payableAmount = data["Amount"]
updatedBalance = balance - payableAmount
transactionRef = coRiderMainDocRef.collection("Transactions").doc()
transactionRef.set({
"Message": "Paid for Ride",
"Amount": payableAmount,
"RideId": rideId,
"Time": SERVER_TIMESTAMP
})
rideDoc.update({"Updated": ride_data["Updated"] + 1})
coRiderMainDocRef.update({"IsOnRide": [False, rideId], "Balance": updatedBalance})
coriderRef.update({"Status": "Completed", "DropTime": SERVER_TIMESTAMP})
return jsonify({"message": "Ride is completed"}), 200
else:
return jsonify({"error": "Error in ride completion"}), 500
return None
@app.route('/complete_driver_ride', methods=['GET'])
def complete_driver_ride():
rideId = request.args.get('rideId')
rideDocRef = rideRef.document(rideId)
ride = rideDocRef.get()
if(ride.exists):
data = ride.to_dict()
if "Driver" in data:
user_doc = data["Driver"]
rideDocRef.update({"Status": "Completed"})
user_doc.update({"IsOnRide": [False, rideId]})
return jsonify({"message": "Ride completed successfully"}), 200
else:
return jsonify({"err": "Ride is not started"}), 500
return jsonify({"error": "Error on ride completion."}), 500
def fetch_route_coordinates(source_lat, source_lng, destination_lat, destination_lng):
source_str = f"{source_lat},{source_lng}"
destination_str = f"{destination_lat},{destination_lng}"
directions_result = gmaps.directions(
source_str,
destination_str,
mode="driving", # You can change the mode based on your requirements
departure_time=datetime.now(),
)
# Extract relevant information from the directions result
if len(directions_result) > 0:
route = directions_result[0]['legs'][0]
steps = route['steps']
encoded_polyline = directions_result[0]['overview_polyline']['points']
decoded_polyline = polyline.decode(encoded_polyline)
if len(decoded_polyline) > 0:
# Insert source coordinates at the beginning
decoded_polyline.insert(0, (source_lat, source_lng))
# Append destination coordinates at the end
decoded_polyline.append((destination_lat, destination_lng))
return decoded_polyline
else:
return []
else:
return []
def calculate_bearing(lat1, lon1, lat2, lon2):
"""
Calculate the bearing angle between two sets of coordinates.
"""
lat1_rad = math.radians(lat1)
lon1_rad = math.radians(lon1)
lat2_rad = math.radians(lat2)
lon2_rad = math.radians(lon2)
delta_lon = lon2_rad - lon1_rad
y = math.sin(delta_lon) * math.cos(lat2_rad)
x = math.cos(lat1_rad) * math.sin(lat2_rad) - math.sin(lat1_rad) * math.cos(lat2_rad) * math.cos(delta_lon)
bearing = math.atan2(y, x)
bearing = math.degrees(bearing)
bearing = (bearing + 360) % 360
return bearing
@app.route('/search_rides', methods=['GET'])
def search_rides():
# Get user's source and destination coordinates from the request
user_source_lat = float(request.args.get('s_lat'))
user_source_lng = float(request.args.get('s_lng'))
user_destination_lat = float(request.args.get('d_lat'))
user_destination_lng = float(request.args.get('d_lng'))
query = rideRef.where("Status", "==", "Started")
rides = query.stream()
user_route_coordinates = fetch_route_coordinates(user_source_lat, user_source_lng, user_destination_lat, user_destination_lng)
filtered_rides = []
count = 0
bearing1 = calculate_bearing(user_source_lat,user_source_lng, user_destination_lat, user_destination_lng)
results = []
for ride in rides:
ride_data = ride.to_dict()
if(ride_data["JoinedRiders"] == ride_data["SeatingCapacity"]):
continue
ride_data["Id"] = ride.id
document_route_coordinates = fetch_route_coordinates(ride_data["Source"][0], ride_data["Source"][1], ride_data["Destination"][0], ride_data["Destination"][1])
bearing2 = calculate_bearing(ride_data["Source"][0], ride_data["Source"][1], ride_data["Destination"][0], ride_data["Destination"][1])
angle_difference = abs(bearing1 - bearing2)
threshold = 50
print("angle diff", angle_difference)
if(angle_difference > threshold):
continue
source_proximity = False
for lat, lng in document_route_coordinates:
distance = geodesic((user_source_lat, user_source_lng), (lat, lng)).meters
if distance <= 700:
source_proximity = True
break
destination_proximity = False
for lat, lng in document_route_coordinates:
distance = geodesic((user_destination_lat, user_destination_lng), (lat, lng)).meters
if distance <= 700:
destination_proximity = True
break
if source_proximity and destination_proximity:
ride_data = get_ride(ride.id)
results.append({
"Source": ride_data["Source"],
"Destination": ride_data["Destination"],
"Status": ride_data["Status"],
"Id": ride_data["Id"],
"Driver": ride_data["Driver"],
"Vehicle":ride_data["Vehicle"],
"JoinedRiders": ride_data["JoinedRiders"],
"SeatingCapacity": ride_data["SeatingCapacity"],
"CoRiders": ride_data["CoRiders"],
})
count = count + 1
if(count > 4):
break
return jsonify({'rides': results})
if __name__ == "__main__":
app.run(debug=True)