-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartResponse.py
152 lines (112 loc) · 4.83 KB
/
smartResponse.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
import getFlights
# import getHotels
# import getCarRentals
import toDate
import pprint
import json
import convertDate
import pprint
# def codeToFullName(originAirport):
# return originAirport
# airportsJsonData = json.load(open("utils/airportsJson.json"))
# for state in airportsJsonData: # Turn origin airport into real name rather than code
# for airportKey, airportValue in airportsJsonData[state].items():
# if airportValue == originAirport:
# originAirport = airportKey + "(" + airportValue + ")"
# return originAirport
# return originAirport
# def cheapestFlightResponse(comingFrom, goingTo, date):
# outOf = comingFrom
# to = goingTo
# leaves = convertDate.convertDate(date)
# flightJson = getFlights.getCheapestFlights(outOf, to, leaves)
# if "message" in flightJson.keys():
# return [flightJson['message']]
# outputList = []
# for result in flightJson.get("results", [])[:3]: #This is fine
# price = result.get("fare", {}).get("total_price", "Unknown")
# for flights in result.get("itineraries", []):
# connecting = flights.get("outbound", {}).get("flights", [])
# isConnecting = "Connecting Flight" if len(connecting) > 1 else "Non Stop"
# builtFlight = "Price: {}\n{}\n".format( price, isConnecting)
# for flight in connecting:
# aircraftType = flight.get("aircraft", "Unknown")
# leaves_at = toDate.toDate(flight.get("departs_at", "Unknown"))
# seatsRemaining = flight.get("booking_info", {}).get("seats_remaining", "Unknown")
# travel_class = flight.get("booking_info", {}).get("travel_class", "Unknown")
# destination = flight.get("destination", {}).get("airport", "Unknown")
# flightNumber = flight.get("flight_number", "Unknown")
# airline = flight.get("operating_airline", "Unknown")
# origin = flight.get("origin", {}).get("airport", "Unknown")
# terminal = flight.get("origin", {}).get("terminal", "Unknown")
# flightInfo = """
# Aircraft: {}
# Departing at: {}
# Seats Remaining: {}
# Class: {}
# Origin: {}
# Destinaton: {}
# Flight Number: {}
# Airline: {}
# Terminal: {}
# """.format(aircraftType, leaves_at, seatsRemaining, travel_class, origin, destination, flightNumber, airline, terminal)
# builtFlight += flightInfo
# outputList.append(builtFlight)
# return outputList
def inspirationFlightResponse(comingFrom, date, price, duration = None):
outOf = comingFrom
leaves = convertDate.convertDate(date)
money = price
if duration is not None:
flightJson = getFlights.getInspirationFlights(outOf, leaves, price, duration)
else:
flightJson = getFlights.getInspirationFlights(outOf, leaves, price)
if "message" in flightJson.keys():
return [flightJson['message']]
outputList = []
listToSort = []
currentPrice = 99999999.00
for result in flightJson.get("results", [])[:3]: #This is fine
price = result.get("price", "Unknown")
airline = result.get("airline", "Unknown")
leaves_at = toDate.toDate(result.get("departure_date", "Unknown"))
to = result.get("destination", "Unknown")
come_back = toDate.toDate(result.get("return_date", "Unknown"))
flightInfo = """
Price: {}
Airline: {}
Departing on: {}
Origin: {}
Destinaton: {}
Return Date: {}
""".format(price, airline, leaves_at, outOf, to, come_back)
# For cheapesst flight out of all fo them
# if float(price) < float(currentPrice):
# # print(price)
# currentPrice = price
# if len(outputList) != 0:
# outputList.pop()
# else:
# outputList.append(flightInfo)
#For first x number of the list
listToSort.append(price)
listToSort.sort(); # Sort in greatest to least order
listToSort[:3] # First 3 elements of the list of prices
for num in listToSort:
for element in flightJson.get("results", []):
if num == element.get("price"):
price = element.get("price", "Unknown")
airline = element.get("airline", "Unknown")
leaves_at = toDate.toDate(element.get("departure_date", "Unknown"))
to = element.get("destination", "Unknown")
come_back = toDate.toDate(element.get("return_date", "Unknown"))
flightInfo = """
Price: {}
Airline: {}
Departing on: {}
Origin: {}
Destinaton: {}
Return Date: {}
""".format(price, airline, leaves_at, outOf, to, come_back)
outputList.append(flightInfo)
return outputList