Ejemplo n.º 1
0
 def getReader(self,file_path):
     filename,ext = os.path.splitext(file_path)
     if ext in ('.xls','.xlsx'):
         reader = XlsReader(file_path)
     else:
         reader = CsvReader(file_path)
     reader.index = {self._importer_keycb(k):v for k,v in reader.index.items()}
     return reader
Ejemplo n.º 2
0
def importXlsProvince(db, docname):
    reader = XlsReader(docname)
    prov = db.table('glbl.provincia')
    reg = db.table('glbl.regione')
    regioni_dict = dict()

    for row in reader():
        row = dict(row)
        cod_reg = '%02i' % row['cod_reg']
        if not cod_reg in regioni_dict:
            reg_rec = reg.record(where='$codice_istat=:cod_reg',
                                 cod_reg=cod_reg,
                                 for_update=True).output('dict')
            oldrec = dict(reg_rec)
            reg_rec['zona_numero'] = row['cod_rip']
            reg_rec['zona'] = row['zona']
            reg_rec['nuts'] = row['nuts2']
            reg_rec['nome'] = row['regione_desc']
            reg.update(reg_rec, oldrec)
            print 'oldregione', oldrec, 'regione updated', reg_rec
            regioni_dict[cod_reg] = reg_rec
        rec_prov = dict()
        rec_prov['sigla'] = row['prov_sigla']
        rec_prov['codice_istat'] = '%03i' % row['cod_prov']
        rec_prov['nome'] = row['prov_desc']
        rec_prov['nuts'] = row['nuts3']
        rec_prov['regione'] = regioni_dict[cod_reg]['sigla']
        prov.insertOrUpdate(rec_prov)
Ejemplo n.º 3
0
 def rpc_xlsRows(self, docname=None):
     result = Bag()
     reader = XlsReader(docname)
     headers = reader.headers
     result['struct'] = self.newGridStruct()
     r = result['struct'].view().rows()
     for colname in headers:
         r.cell(colname, name=colname, width='5em')
     for i, row in enumerate(reader()):
         result.setItem('store.r_%i' % i, None, dict(row))
     return result
Ejemplo n.º 4
0
def importXlsComuni(db, docname):
    reader = XlsReader(docname)
    comune = db.table('glbl.comune')
    province_dict = db.table('glbl.provincia').query().fetchAsDict(
        'codice_istat')
    print 'province', province_dict
    for row in reader():
        row = dict(row)
        row['litoraneo'] = True if row['litoraneo'] is 1 else False
        row['capoluogo'] = True if row['capoluogo'] is 1 else False
        row['sigla_provincia'] = province_dict[
            row['codice_provincia']]['sigla']
        comune.insert(row)
Ejemplo n.º 5
0
def importXlsNuts(db, docname):
    reader = XlsReader(docname)
    nuts = db.table('glbl.nuts')

    for row in reader():
        rec = dict()
        row = dict(row)
        rec['code'] = row['code']
        rec['description'] = row['description']
        rec['level'] = row['level']
        rec['country'] = row['country']
        rec['country_iso'] = row['country']
        if rec['country_iso'] == 'EL':
            rec['country_iso'] = 'GR'
        if rec['country_iso'] == 'UK':
            rec['country_iso'] = 'GB'
        nuts.insert(rec)