Exemplo n.º 1
0
    def handle_noargs(self, **options):
        data_reader = csv.reader(open(SOURCE_FILE))
        
        def clean_int(value):
            if value <> '':
                value = int(value.replace(',', '').replace(' ', ''))
            else:
                value = None
            return value

        for i, row in enumerate(data_reader):
            if i == 0:
                header_row = row;            
            else:
                record = KidsHealthInsurance()
                for j,col in enumerate(row):
                    setattr(record, header_row[j], col)
                record.save()
 def handle_noargs(self, **options):
     data_reader = csv.reader(open(SOURCE_FILE))
     
     def clean_num(value):
         if value.strip()=='':
             value=None
         elif value.find(".") <> -1:
             value = value.replace(",","")
             value = float(value)
         else:
             value = value.replace(",","")
             value = int(value)
         return value
     
     for i, row in enumerate(data_reader):
         if i == 0:
             header_row = row;            
         else:
             record = KidsHealthInsurance()
             for j,col in enumerate(row):
                 if j == 0:
                     setattr(record, header_row[j], col)
                 else:
                     setattr(record, header_row[j], clean_num(col))
             record.all_people = record.all_people * 1000
             record.not_covered = record.not_covered * 1000
             record.covered = record.covered * 1000
             record.private = record.private * 1000
             record.private_employment = record.private_employment * 1000
             record.direct_purchase = record.direct_purchase * 1000
             record.govt = record.govt * 1000
             record.medicaid = record.medicaid * 1000
             record.medicare = record.medicare * 1000
             record.military = record.military * 1000
             record.save()
Exemplo n.º 3
0
    def handle_noargs(self, **options):
        data_reader = csv.reader(open(SOURCE_FILE))

        def clean_num(value):
            if value.strip() == '':
                value = None
            elif value.find(".") <> -1:
                value = value.replace(",", "")
                value = float(value)
            else:
                value = value.replace(",", "")
                value = int(value)
            return value

        for i, row in enumerate(data_reader):
            if i == 0:
                header_row = row
            else:
                record = KidsHealthInsurance()
                for j, col in enumerate(row):
                    if j == 0:
                        setattr(record, header_row[j], col)
                    else:
                        setattr(record, header_row[j], clean_num(col))
                record.all_people = record.all_people * 1000
                record.not_covered = record.not_covered * 1000
                record.covered = record.covered * 1000
                record.private = record.private * 1000
                record.private_employment = record.private_employment * 1000
                record.direct_purchase = record.direct_purchase * 1000
                record.govt = record.govt * 1000
                record.medicaid = record.medicaid * 1000
                record.medicare = record.medicare * 1000
                record.military = record.military * 1000
                record.save()