Esempio n. 1
0
def create_city_db(state_db, country_db):
    city_db = PlaceDB()
    # Field 14 is population, see
    # http://download.geonames.org/export/dump/readme.txt
    # for reference
    for (
            city_name,
            country_code,
            state_code_part,
            population,
    ) in _read_data_file(
            CITIES_FILE,
            usecols=[1, 8, 10, 14],
            population_field_num=14,
    ):
        if state_code_part:
            state_code = '{}.{}'.format(country_code, state_code_part)
            state = state_db[state_code]
        else:
            state = None
        country = country_db[country_code]
        city_db.add(
            City(city_name, city_name, canonize_location_name(city_name),
                 int(population), state, country))
    return city_db
Esempio n. 2
0
def create_state_db(country_db):
    state_db = PlaceDB()
    for data in _read_data_file(STATES_FILE):
        country_code = data[0].split('.')[0]
        state_db.add(
            State(data[0], data[1], canonize_location_name(data[1]),
                  country_db[country_code]))
    return state_db
Esempio n. 3
0
def create_country_db():
    country_db = PlaceDB()
    for (
            country_name,
            country_code,
            population,
    ) in _read_data_file(COUNTRIES_FILE, usecols=[4, 0, 7]):
        country_db.add(
            Country(country_code, country_name,
                    canonize_location_name(country_name), int(population)))
    return country_db
Esempio n. 4
0
def create_country_abbreviations_db(country_db):
    country_abbreviations_db = PlaceDB()
    for (
            country_abbrevation,
            country_code,
    ) in _read_data_file(COUNTRIES_ABBREVIATIONS_FILE):
        country = country_db[country_code]
        country_abbreviations_db.add(
            PlaceLink(country_abbrevation, country_abbrevation,
                      country_abbrevation, country))
    return country_abbreviations_db
Esempio n. 5
0
def create_city_abbreviations_db(city_db):
    city_abbreviations_db = PlaceDB()
    for (
            city_abbrevation,
            city_name,
    ) in _read_data_file(CITIES_ABBREVIATIONS_FILE):
        city = city_db[canonize_location_name(city_name)]
        city_abbreviations_db.add(
            PlaceLink(city_abbrevation, city_abbrevation, city_abbrevation,
                      city))
    return city_abbreviations_db
Esempio n. 6
0
def create_nationality_db(country_db):
    nationality_db = PlaceDB()
    for (
            nationality_name,
            country_code,
    ) in _read_data_file(NATIONALITIES_FILE):
        pass
        country = country_db[country_code]
        nationality_db.add(
            PlaceLink(nationality_name, nationality_name,
                      canonize_location_name(nationality_name), country))
    return nationality_db