コード例 #1
0
ファイル: pathing.py プロジェクト: apsun/Ticketizer
 def get_path(self, train):
     query = TrainQuery()
     query.pricing = self.pricing
     substations = self.__get_substations(train)
     try:
         return self.__get_path_recursive([train], substations, query, True)
     except StopPathSearch:
         return None
コード例 #2
0
ファイル: main.py プロジェクト: apsun/Ticketizer
def query(station_list, retry, auto):
    # Construct query object
    query_obj = TrainQuery()
    query_obj.date = select_train_date(auto)
    query_obj.departure_station = select_departure_station(station_list, auto)
    query_obj.destination_station = select_destination_station(station_list, auto)
    query_obj.exact_departure_station = config.get("exact_departure_station", False)
    query_obj.exact_destination_station = config.get("exact_destination_station", False)

    filter_obj = create_train_filters()
    sorter_obj = create_train_sorters()
    custom_filter = config.get("custom_filter")
    custom_sorter = config.get("custom_sorter")
    sleep_time = config.get("search_retry_rate", 1)

    while True:
        try:
            # Get raw train list
            train_list = query_obj.execute()
        except DateOutOfRangeError:
            # Invalid date provided, prompt the user for a new one
            print(localization.DATE_OUT_OF_RANGE.format(timeconverter.date_to_str(query_obj.date)))
            # Forcibly disable auto mode, to avoid re-using an
            # invalid date again
            query_obj.date = select_train_date(False)
            continue

        # Now we filter the resulting list
        original_count = len(train_list)
        train_list = filter_obj.filter(train_list)
        if custom_filter is not None:
            custom_filter(train_list)
        filtered_count = len(train_list)

        # Make sure there's at least one train
        if filtered_count == 0:
            if original_count > 0:
                print(localization.ALL_TRAINS_FILTERED.format(original_count))
                if retry:
                    print(localization.RETRYING_SEARCH.format(sleep_time))
                    time.sleep(sleep_time)
                    continue
                else:
                    return None
            else:
                print(localization.NO_TRAINS_FOUND)
                return None

        # After filtering the trains, we sort the list
        sorter_obj.sort(train_list)
        if custom_sorter is not None:
            custom_sorter(train_list)

        return train_list