|
| 1 | +class Itinerary: |
| 2 | + """ |
| 3 | + This class represents a single itinerary object that users can create. |
| 4 | +
|
| 5 | + Args: |
| 6 | + name (str): The name assigned to the itinerary. |
| 7 | + location (str): The main city/country the holiday takes place. |
| 8 | + summary (str, optional): A brief summary of the travel plan. |
| 9 | + start_date (str): The date the holiday begins in 'DD-MM-YYYY' format. |
| 10 | + end_date (str): The date the holiday ends in 'DD-MM-YYYY' format. |
| 11 | + flights (dict): A nested dictionary type containing flights and flight details: |
| 12 | + flight_name (key, dict type): Contains the flight name (departure-arrival location format, e.g. 'Perth to Sydney') |
| 13 | + departure_airport (str): Departure airport name. |
| 14 | + departure_date (datetime): Date & time of flight departure in 'DD-MM-YYYY HH:MM' format. |
| 15 | + arrival_airport (str): Arrival airport name. |
| 16 | + arrival_date (datetime): Date & time of flight arrival in 'DD-MM-YYYY HH:MM' format. |
| 17 | + attractions (dict): Nested dictionary of attractions. Each dictionary key (name of attraction) contains: |
| 18 | + attraction_name (str, dict): Name of attraction (key) and a dictionary containing attraction details: |
| 19 | + address (str): Address of attraction. |
| 20 | + attraction_summary(str): Short description of attraction. |
| 21 | + attraction_tags (list): List of tags (str type) that catergorise the attraction. |
| 22 | + """ |
| 23 | + |
| 24 | + def __init__(self, name, location, summary, start_date, end_date, flights, attractions): |
| 25 | + self.name = name |
| 26 | + self.location = location |
| 27 | + self.summary = summary |
| 28 | + self.start_date = start_date |
| 29 | + self.end_date = end_date |
| 30 | + self.flights = flights |
| 31 | + self.attractions = attractions |
| 32 | + pass |
| 33 | + |
| 34 | + def to_dict(self): |
| 35 | + """ |
| 36 | + Converts the Itinerary object into a dictionary. |
| 37 | +
|
| 38 | + Returns: |
| 39 | + dict: A dictionary containing itinerary details with these keys: |
| 40 | + 'name', 'location', 'summary', 'start-date', 'end-date', 'flights', and 'attractions'. |
| 41 | + """ |
| 42 | + return { |
| 43 | + "name": self.name, |
| 44 | + "location": self.location, |
| 45 | + "summary": self.summary, |
| 46 | + "start_date": self.start_date, |
| 47 | + "end_date": self.end_date, |
| 48 | + "flights": self.flights, |
| 49 | + "attractions": self.attractions |
| 50 | + } |
| 51 | + |
| 52 | + @staticmethod |
| 53 | + def from_dict(itinerary_info): |
| 54 | + """ |
| 55 | + Creates an Itinerary object from the dictionary representation. |
| 56 | +
|
| 57 | + Args: |
| 58 | + itinerary_info (dict): A dictionary containing itinerary info with these keys: |
| 59 | + 'name', 'location', 'summary', 'start-date', 'end-date', 'flights', and 'attractions'. |
| 60 | +
|
| 61 | + Returns: |
| 62 | + Itinerary: A new Itinerary object created from the dictionary data. |
| 63 | + """ |
| 64 | + # TODO: Re-write to accommodate the dictionary type, and load its attributes according to their type. |
| 65 | + # Reference that might help: https://stackoverflow.com/questions/56640436/how-to-generically-serialize-and-de-serialize-objects-from-dictionaries |
| 66 | + |
| 67 | + return Itinerary( |
| 68 | + itinerary_info["name"], |
| 69 | + itinerary_info["location"], |
| 70 | + itinerary_info["summary"], |
| 71 | + itinerary_info["start-date"], |
| 72 | + itinerary_info["end_date"], |
| 73 | + itinerary_info["flights"], |
| 74 | + itinerary_info["attractions"] |
| 75 | + ) |
0 commit comments