Пример #1
0
def train_to_string(train_data):
    duration = str(train_data["minuteDuration"]//60) + \
        "h"+str(train_data["minuteDuration"] % 60)
    string = "Train ("+",".join(train_data["type"])+") numero "+",".join(train_data["numbers"])+":\n"+"Depart de "+Station.get_name_by_code(train_data["origin_code"])+" : " + \
        train_data["departureDate"]+"\n"+"Arrivee a "+Station.get_name_by_code(
            train_data["destination_code"])+" : " + train_data["arrivalDate"]+"\n"+"Duree : "+duration+"\n"+"Prix :\n"
    for price in train_data["prices"]:
        string += str(price[1]) + " restants à " + str(price[0]) + "e\n"
    # print(string)
    return string
Пример #2
0
 def search(date: DateTime, origin_code: str, destination_code: str) \
         -> list:
     """
     Search for trains
     :param date: date to search, datetime object
     :param origin_code: code of the origin (i.e. FRXXX)
     :param destination_code: code of the destination (i.e. FRXXX)
     :return: list of available trains
     """
     origin = {
         "code": origin_code,
         "name": Station.get_name_by_code(origin_code)
     }
     destination = {
         "code": destination_code,
         "name": Station.get_name_by_code(destination_code)
     }
     response_json = Travel._query(date, origin, destination).json()
     if "trainProposals" in response_json:
         trains = response_json["trainProposals"]
         return trains
     else:
         raise ValueError('Bad response from request')