-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpx_response.py
37 lines (29 loc) · 988 Bytes
/
gpx_response.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
import json
import logging
from model import Flight
class GpxResponse:
"""GpxRespone wrapper generated from a json data."""
def __init__(self, json_response):
"""Constructor of the class.
Args:
json_response: response that contains the GPX flight options.
"""
# Raw dictionary returned on the response.
self.json_data_ = json.loads(json_response)
self.flight_list_ = self._ParseFlights(self.json_data_)
def _ParseFlights(self, json_data):
"""Parses the JSON data extracting the resulting flights from it.
Args:
json_data: Dictionary with the json_data.
"""
flights = []
for trip_option in json_data["trips"]["tripOption"]:
flight = Flight(trip_option)
flights.append(flight)
return flights
def Print(self):
"""Prints the dictionary containing the response."""
print self.json_data_
def GetFlights(self):
"""Returns the flights contained in the response."""
return self.flight_list_