Beispiel #1
0
                station['mode'] = 'metro'
            elif re.match("TXR|STR|FTD|FBT|FER|AIR|GAT", row[31]):
                # currently don't support taxis, ferries, or airports
                continue
            else:
                print("Unrecognized type: ", row[31])

            stations[station['mode']].append(station)

    for m in ['train', 'bus', 'metro']:
        with open(basepath + pluralize(m) + '/' + country + '.json', 'w') as f:
            f.write(json.dumps(stations[m]))


def do_import(mongo_uri, basepath):
    station_parsers = [
        ['UK', parse_uk],
    ]

    for parser in station_parsers:
        stations = parser[1](parser[0], basepath)
        print("Prepared", parser[0], "for import")


if __name__ == "__main__":
    from lib import get_mongo_config, get_basepath
    mongo_uri = get_mongo_config()
    basepath = get_basepath()

    do_import(mongo_uri, basepath)
Beispiel #2
0
    return stations

def do_import(mongo_uri, basepath):
    station_parsers = [
        ['London', parse_london_bikes],
        ['Barcelona', parse_bcn_bikes],
        ['Valencia', parse_valencia_bikes],
        ['Malaga', parse_malaga_bikes],
        ['Zaragoza', parse_zaragoza_bikes],
    ]

    client = pymongo.MongoClient(mongo_uri)
    db = client.openmotion
    bikes = db.bikes

    for parser in station_parsers:
        bikes.insert(parser[1](basepath))

    client.disconnect()

if __name__ == "__main__":
    from lib import get_mongo_config, get_basepath, mongo_drop, mongo_index
    mode = 'bikes'
    mongo_uri = get_mongo_config()
    basepath = get_basepath() + mode + '/'

    mongo_drop(mongo_uri, mode)
    do_import(mongo_uri, basepath)
    mongo_index(mongo_uri, mode)
Beispiel #3
0
#!/usr/bin/env python3

from lib import get_mongo_config, get_basepath, drop_and_recreate

if __name__ == "__main__":
    mongo_uri = get_mongo_config()
    basepath = get_basepath()

    import countries
    countries.do_import(mongo_uri, basepath)

    transports = ['bikes', 'metros', 'trains', 'buses']
    for t in transports:
        drop_and_recreate(mongo_uri, t)

    modules = map(__import__, transports)
    for m in modules:
        print("Importing", m.__name__)
        m.do_import(mongo_uri, basepath + m.__name__ + '/')
Beispiel #4
0

def do_import(mongo_uri, basepath):
    station_parsers = [
        ['London', parse_london_bikes],
        ['Barcelona', parse_bcn_bikes],
        ['Valencia', parse_valencia_bikes],
        ['Malaga', parse_malaga_bikes],
        ['Zaragoza', parse_zaragoza_bikes],
    ]

    client = pymongo.MongoClient(mongo_uri)
    db = client.openmotion
    bikes = db.bikes

    for parser in station_parsers:
        bikes.insert(parser[1](basepath))

    client.disconnect()


if __name__ == "__main__":
    from lib import get_mongo_config, get_basepath, mongo_drop, mongo_index
    mode = 'bikes'
    mongo_uri = get_mongo_config()
    basepath = get_basepath() + mode + '/'

    mongo_drop(mongo_uri, mode)
    do_import(mongo_uri, basepath)
    mongo_index(mongo_uri, mode)