forked from elmau/empresa-libre
Read csv to dict
This commit is contained in:
parent
4f40bc3bfa
commit
aa68225571
|
@ -31,6 +31,7 @@ import smtplib
|
|||
import sqlite3
|
||||
import subprocess
|
||||
import threading
|
||||
import unicodedata
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
from xml.sax.saxutils import escape
|
||||
|
@ -760,3 +761,21 @@ def get_status_sat(xml):
|
|||
return node.text
|
||||
|
||||
|
||||
def spaces(value):
|
||||
return '\n'.join([' '.join(l.split()) for l in value.split('\n')])
|
||||
|
||||
|
||||
def to_slug(string):
|
||||
value = (unicodedata.normalize('NFKD', string)
|
||||
.encode('ascii', 'ignore')
|
||||
.decode('ascii').lower())
|
||||
return value.replace(' ', '_')
|
||||
|
||||
|
||||
def read_csv(path, args={'delimiter': '|'}):
|
||||
with open(path) as f:
|
||||
reader = csv.DictReader(f, **args)
|
||||
# ~ rows = tuple(csv.reader(f, **args))
|
||||
rows = [r for r in reader]
|
||||
return rows
|
||||
|
||||
|
|
|
@ -10523,6 +10523,26 @@ def _import_clients(rfc, path):
|
|||
conectar(args)
|
||||
log.info('Importando clientes...')
|
||||
|
||||
data = utils.read_csv(path)
|
||||
for i, row in enumerate(data):
|
||||
if i == 0:
|
||||
continue
|
||||
print(row)
|
||||
|
||||
# ~ w = ((Socios.rfc==fields['rfc']) & (Socios.slug==fields['slug']))
|
||||
# ~ if Socios.select().where(w).exists():
|
||||
# ~ msg = 'Ya existe el RFC y Razón Social'
|
||||
# ~ data = {'ok': False, 'row': {}, 'new': True, 'msg': msg}
|
||||
# ~ return data
|
||||
|
||||
# ~ try:
|
||||
# ~ obj = Socios.create(**fields)
|
||||
# ~ except IntegrityError as e:
|
||||
# ~ msg = 'Ocurrio un error, al dar de alta el emisor'
|
||||
# ~ data = {'ok': False, 'row': {}, 'new': True, 'msg': msg}
|
||||
# ~ return data
|
||||
|
||||
break
|
||||
|
||||
desconectar()
|
||||
log.info('Proceso terminado correctamente...')
|
||||
|
|
Loading…
Reference in New Issue