def generate_query_for_variable(variable_name, config): vdef = parse_variables.variable_definition(variable_name, config) if vdef is None: return None q = QUERY_TEMPLATE % { 'tablename': (vdef['entname'] + vdef['name']).decode('windows-1252'), 'variable': (vdef['entname'] + '.' + vdef['name']).decode('windows-1252'), 'outfile': (vdef['entname'] + '-' + vdef['name']).decode('windows-1252'), 'label': vdef['label'].decode('windows-1252') } return q
def dbf_csv(variable_name, config): vdef = parse_variables.variable_definition(variable_name, config) table = dbf.Table(os.path.join(DBF_PATH, dbf_fname(vdef["entname"], vdef["name"]))) table.open() with open(os.path.join(CSV_PATH, csv_fname(vdef["entname"], vdef["name"])), "w") as f: w = unicodecsv.writer(f) w.writerow(["radio"] + vdef["value_labels_list"] + ["TOTAL"]) for row in table: w.writerow(row)
def dbf_csv(variable_name, config): vdef = parse_variables.variable_definition(variable_name, config) table = dbf.Table(os.path.join(DBF_PATH, dbf_fname(vdef['entname'], vdef['name']))) table.open() with open(os.path.join(CSV_PATH, csv_fname(vdef['entname'], vdef['name'])), 'w') as f: w = unicodecsv.writer(f) w.writerow(['radio'] + vdef['value_labels_list'] + ['TOTAL']) for row in table: w.writerow(row)
table.open() with open(os.path.join(CSV_PATH, csv_fname(vdef["entname"], vdef["name"])), "w") as f: w = unicodecsv.writer(f) w.writerow(["radio"] + vdef["value_labels_list"] + ["TOTAL"]) for row in table: w.writerow(row) if __name__ == "__main__": config = parse_variables.parse_ini("variables.ini") for variable in [s for s in config.sections() if s.startswith("Variable")]: vdef = parse_variables.variable_definition(variable, config) if vdef is None: continue dbf_path = os.path.join(DBF_PATH, dbf_fname(vdef["entname"], vdef["name"])) if not os.path.exists(dbf_path): continue if vdef["entname"] not in ("VIVIENDA", "HOGAR", "PERSONA"): continue print >>sys.stderr, "Exportando tabla %s.%s" % (config.get(variable, "entname"), config.get(variable, "name")) dbf_csv(variable, config)
with open(os.path.join(CSV_PATH, csv_fname(vdef['entname'], vdef['name'])), 'w') as f: w = unicodecsv.writer(f) w.writerow(['radio'] + vdef['value_labels_list'] + ['TOTAL']) for row in table: w.writerow(row) if __name__ == '__main__': config = parse_variables.parse_ini('variables.ini') for variable in [s for s in config.sections() if s.startswith('Variable')]: vdef = parse_variables.variable_definition(variable, config) if vdef is None: continue dbf_path = os.path.join(DBF_PATH, dbf_fname(vdef['entname'], vdef['name'])) if not os.path.exists(dbf_path): continue if vdef['entname'] not in ('VIVIENDA', 'HOGAR', 'PERSONA'): continue print >>sys.stderr, "Exportando tabla %s.%s" % (config.get(variable, 'entname'), config.get(variable, 'name'))