Created
August 26, 2020 18:24
-
-
Save pyjavo/7db6a452135f56fcf2c849da5f0220fb to your computer and use it in GitHub Desktop.
Snippet de Dario
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Full path and name to your csv file | |
csv_filepathname="" | |
# Full path to your django project directory | |
home="" | |
import sys,os | |
sys.path.append(home) | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' | |
import django | |
django.setup() | |
from localizacion.models import es_departamento | |
import csv | |
dataReader = csv.reader(open(csv_filepathname), delimiter=';', quotechar='"') | |
def utf8_encode(val): | |
try: | |
tmp = val.decode('utf8') | |
except: | |
try: | |
tmp = val.decode('latin1') | |
except: | |
tmp= val.decode('ascii', 'ignore') | |
tmp = tmp.encode('utf8') | |
return tmp | |
for row in dataReader: | |
depto = es_departamento() | |
depto.A_codigoDane = row[0] | |
depto.A_nombre = utf8_encode(row[1]) | |
print "%s " % (depto.A_codigoDane) | |
depto.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment