Exemple #1
0
def detail(database_path, parameters_path, code_train):

    # Test : database
    if not os.path.exists(database_path):
        print "snail: error: database doesn't exist. Create it with : snail init."
        sys.exit(1)

    # Test : parameters.json
    if not os.path.exists(parameters_path):
        print "snail: error: parameters.json doesn't exist. Grab it from anywhere."
        sys.exit(1)

    # Connection to the base
    connection = sqlite3.connect(database_path)
    connection.row_factory = sqlite3.Row

    # Transforms stations list into dictionnary
    stations = {}
    for station in database.fetch_all_stations(connection):
        code = station["code"]
        name = station["name"]
        stations[code] = name

    # Get informations for this train
    train_infos = services.fetch_train_infos(parameters_path, code_train)

    # Print list of next stop for this train
    stops = train_infos["data"]
    if stops and not len(stops) == 0:
        print "%d stop(s)" % len(stops)
        for stop in stops:
            __print_stop(stop, stations)

    # Close the connection
    connection.close()
Exemple #2
0
def detail(database_path, parameters_path, code_train):
    
    # Test : database
    if not os.path.exists(database_path):
        print "snail: error: database doesn't exist. Create it with : snail init."
        sys.exit(1)

    # Test : parameters.json
    if not os.path.exists(parameters_path):
        print "snail: error: parameters.json doesn't exist. Grab it from anywhere."
        sys.exit(1)

    # Connection to the base
    connection = sqlite3.connect(database_path)
    connection.row_factory = sqlite3.Row
       
    # Transforms stations list into dictionnary
    stations = {}
    for station in database.fetch_all_stations(connection):
        code = station['code']
        name = station['name']
        stations[code] = name

    # Get informations for this train 
    train_infos = services.fetch_train_infos(parameters_path, code_train)

    # Print list of next stop for this train
    stops = train_infos['data']
    if stops and not len(stops) == 0:
        print "%d stop(s)" % len(stops)
        for stop in stops:
            __print_stop(stop, stations)
    
    # Close the connection
    connection.close()
Exemple #3
0
def next(database_path, parameters_path, code_station):

    # Test : database
    if not os.path.exists(database_path):
        print "snail: error: database doesn't exist. Create it with : snail init."
        sys.exit(1)

    # Test : parameters.json
    if not os.path.exists(parameters_path):
        print "snail: error: parameters.json doesn't exist. Grab it from anywhere."
        sys.exit(1)

    # Connection to the base
    connection = sqlite3.connect(database_path)
    connection.row_factory = sqlite3.Row

    # Transforms stations list into dictionnary
    global stations
    stations[''] = ''
    for station in database.fetch_all_stations(connection):
        code = station['code']
        name = station['name']
        stations[code] = name

    # Only if code exits in database
    if code_station in stations:

        # Get informations for this station
        station_infos = services.fetch_station_infos(parameters_path,
                                                     code_station)

        # Print informations of the station
        station = database.fetch_station_by_code(connection, code_station)
        __print_station(station)

        # Print list of next trains for this station
        trains = station_infos['data']
        if trains and not len(trains) == 0:
            print "\n%d train(s)" % len(trains)
            codes = []
            for train in trains:

                # Get some ID for the train
                number = train['trainNumber']
                code = train['trainMissionCode']

                # Get some extra infos from train service
                departure = ""
                position = ""
                status = "."

                if not code in codes:

                    # Keep the code
                    codes.append(code)

                    # Get stops for this train
                    stops = services.fetch_train_infos(parameters_path,
                                                       number)['data']

                    # Find position
                    position = __get_train_position(stops)

                    # Find departure
                    departure = __get_train_departure(stops)

                    # Find status
                    status = __get_train_status(departure, position,
                                                train['trainMention'], stops)

                # Print informations
                train['trainDeparture'] = departure
                train['trainStatus'] = status
                train['trainPosition'] = position
                __print_train(train)

        # Print informations on the track
        infos = station_infos['list']
        if infos and not len(infos) == 0:
            print "\n%d information(s)" % len(infos)
            for information in infos:
                __print_information(information)

    # Close the connection
    connection.close()
Exemple #4
0
def next(database_path, parameters_path, code_station):

    # Test : database
    if not os.path.exists(database_path):
        print "snail: error: database doesn't exist. Create it with : snail init."
        sys.exit(1)

    # Test : parameters.json
    if not os.path.exists(parameters_path):
        print "snail: error: parameters.json doesn't exist. Grab it from anywhere."
        sys.exit(1)

    # Connection to the base
    connection = sqlite3.connect(database_path)
    connection.row_factory = sqlite3.Row

    # Transforms stations list into dictionnary
    global stations
    stations[""] = ""
    for station in database.fetch_all_stations(connection):
        code = station["code"]
        name = station["name"]
        stations[code] = name

    # Only if code exits in database
    if code_station in stations:

        # Get informations for this station
        station_infos = services.fetch_station_infos(parameters_path, code_station)

        # Print informations of the station
        station = database.fetch_station_by_code(connection, code_station)
        __print_station(station)

        # Print list of next trains for this station
        trains = station_infos["data"]
        if trains and not len(trains) == 0:
            print "\n%d train(s)" % len(trains)
            codes = []
            for train in trains:

                # Get some ID for the train
                number = train["trainNumber"]
                code = train["trainMissionCode"]

                # Get some extra infos from train service
                departure = ""
                position = ""
                status = "."

                if not code in codes:

                    # Keep the code
                    codes.append(code)

                    # Get stops for this train
                    stops = services.fetch_train_infos(parameters_path, number)["data"]

                    # Find position
                    position = __get_train_position(stops)

                    # Find departure
                    departure = __get_train_departure(stops)

                    # Find status
                    status = __get_train_status(departure, position, train["trainMention"], stops)

                # Print informations
                train["trainDeparture"] = departure
                train["trainStatus"] = status
                train["trainPosition"] = position
                __print_train(train)

        # Print informations on the track
        infos = station_infos["list"]
        if infos and not len(infos) == 0:
            print "\n%d information(s)" % len(infos)
            for information in infos:
                __print_information(information)

    # Close the connection
    connection.close()