-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfParser.py
More file actions
49 lines (37 loc) · 1.44 KB
/
fParser.py
File metadata and controls
49 lines (37 loc) · 1.44 KB
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
__author__ = 'Kunya'
import json
from Flight import Flight
class FlightParser:
def __init__(self, jsonFlights):
self.data = jsonFlights# json.loads(jsonFlights)
self.carriers = self.parseCarriers()
self.flights = self.createFlights()
for f in self.flights:
print (f)
def parseCarriers(self):
ret = {}
carriers = self.data['trips']['data']['carrier']
for carrier in carriers:
ret[carrier['code']] = carrier['name']
return ret
def createFlights(self):
allOptions = self.data['trips']['tripOption']
flights = []
for option in allOptions:
price = option['saleTotal']
for slice in option['slice']:
for segment in slice['segment']:
airline = self.carriers.get( segment['flight']['carrier'], segment['flight']['carrier'])
leg = segment['leg'][0]
arrivalTime = leg['arrivalTime']
depTime = leg['departureTime']
dest = leg['destination']
origin = leg['origin']
meal = leg['meal']
f= Flight(depTime, arrivalTime, origin, dest, price , airline, meal)
flights.append(f)
return flights
#with open('C:\Users\Kunya\Desktop\jsonFlights.txt') as json_data:
# d = json.load(json_data)
# f = FlightParser(d)
# print(d)