Exemplo n.º 1
0
def load_french_cities():
    with open(FRENCH_CITIES_FILE_PATH, 'r') as cities_file:
        csv_reader = reader(cities_file, delimiter=',', quoting=csv.QUOTE_ALL)

        for row in csv_reader:
            try:
                zip_code = row[7].split('-')[0]
                city = City(name=unicode(row[4], 'utf-8'),
                            zip_code=zip_code,
                            country=FRANCE_COUNTRY_NAME)
                city.save()
            except:
                traceback.print_exc()
                sys.stderr.write(unicode(row[4], 'utf-8') + u' could not be saved\n')
Exemplo n.º 2
0
def load_spanish_cities():
    with open(SPANISH_CITIES_FILE_PATH, 'r') as cities_file:
        csv_reader = reader(cities_file, delimiter=';', quoting=csv.QUOTE_NONE)

        for row in csv_reader:
            try:
                if row[2] == "false":
                    zip_code = row[3]
                    city = City(name=unicode(row[4], 'utf-8'),
                                zip_code=zip_code,
                                country=SPAIN_COUNTRY_NAME)
                    city.save()
            except:
                traceback.print_exc()
                sys.stderr.write(unicode(row[4], 'utf-8') + u' could not be saved\n')
Exemplo n.º 3
0
def load_portugues_ciies():
    with open(PORTUGUESE_CITIES_FILE_PATH, 'r') as cities_file:
        csv_reader = reader(cities_file, delimiter=';', quoting=csv.QUOTE_NONE)

        for row in csv_reader:
            try:
                zip_code = row[14]

                print zip_code,  unicode(row[16], 'utf-8')

                city = City(name=unicode(row[16], 'utf-8'),
                            zip_code=zip_code,
                            country=PORTUGAL_COUNTRY_NAME)
                city.save()
            except:
#                traceback.print_exc()
                sys.stderr.write(unicode(row[4], 'utf-8') + u' could not be saved\n')