Skip to content

Instantly share code, notes, and snippets.

@dpineiden
Created March 18, 2016 22:54
Show Gist options
  • Save dpineiden/378078420507f91349d3 to your computer and use it in GitHub Desktop.
Save dpineiden/378078420507f91349d3 to your computer and use it in GitHub Desktop.
import os
from apps.localizacion.models import Region, Comuna
import csv, codecs
def load_places():
dir = os.path.dirname(os.path.abspath(__file__))
print(dir)
comunas_path = dir+'/comunas.txt'
regiones_path = dir+'/regiones.txt'
comunas = codecs.open( comunas_path, 'r' , encoding='utf-8')
regiones = codecs.open( regiones_path, 'r', encoding='utf-8')
for line in regiones:
print(line, end='')
region_tupla = line.split(',')
r = Region()
print(str(len(region_tupla[0])))
r.nombre = region_tupla[0]
r.numero_decimal = str(region_tupla[1].replace("\r\n", ""))
print(r.nombre)
#r.save()
del r
for line in comunas:
print(line, end='')
comuna_tupla = line.split(',')
print(comuna_tupla)
nombre_comuna = comuna_tupla[0]
c = Comuna()
c.nombre = nombre_comuna
c.region = Region.objects.filter( numero_decimal = comuna_tupla[1].replace("\r\n", "") )[0]
c.save()
del c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment