1
+ #This class is responsible for structuring the flight data.
2
+ class FlightData :
3
+
4
+ def __init__ (self ):
5
+ pass
6
+
7
+ def compare (self , price_data , lowest_price ):
8
+ # Normalize API price hike
9
+ lowest_price += lowest_price * 14.8 / 100
10
+ self .price_data = price_data
11
+ self .price_array = []
12
+ self .date_array = []
13
+ for data in self .price_data :
14
+ # print(f"{data['price']} {(data['route'][0]['local_arrival'])[:10]}")
15
+ self .price_array .append (int (data ['price' ]))
16
+ self .date_array .append ((data ['route' ][0 ]['local_arrival' ])[:10 ])
17
+ self .min_price = min (self .price_array )
18
+ return self .min_price < lowest_price
19
+
20
+ def get_data (self ):
21
+ low_limit = self .price_array .index (self .min_price )
22
+ self .price_array .reverse ()
23
+ high_limit = self .price_array .index (self .min_price )
24
+ self .min_price -= self .min_price * 14.8 / 100
25
+ flight_details = {
26
+ 'price' : round (self .min_price ),
27
+ 'cityFrom' : self .price_data [0 ]['route' ][0 ]['cityFrom' ],
28
+ 'cityCodeFrom' : self .price_data [0 ]['route' ][0 ]['cityCodeFrom' ],
29
+ 'cityTo' : self .price_data [0 ]['route' ][0 ]['cityTo' ],
30
+ 'cityCodeTo' : self .price_data [0 ]['route' ][0 ]['cityCodeTo' ],
31
+ 'dateFrom' : self .date_array [low_limit ],
32
+ 'dateTo' : ''
33
+ }
34
+ self .date_array .reverse ()
35
+ flight_details ['dateTo' ] = self .date_array [high_limit ]
36
+ return flight_details
0 commit comments