- Timestamp:
- 2 Feb 2012, 22:40:21 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/tools/fix_import_file.py
r7550 r7572 30 30 """ 31 31 32 import sys33 34 35 if len(sys.argv) != 2:36 print 'Usage: python fix_import_file.py <filename>'37 sys.exit(1)38 39 32 ## 40 33 ## CONFIGURATION SECTION … … 192 185 193 186 194 reader = csv.DictReader(open(INPUT_FILE, 'rb')) 195 writer = None 196 197 for num, row in enumerate(reader): 198 if num == 0: 199 writer = csv.DictWriter(open(OUTPUT_FILE, 'wb'), reader.fieldnames) 200 print "FIELDS: " 201 for x, y in enumerate(reader.fieldnames): 202 print x, y 203 header = convert_fieldnames(reader.fieldnames) 204 writer.writerow(header) 205 for key, value in row.items(): 206 if not key in OPTIONS.keys(): 207 continue 208 conv_name = OPTIONS[key] 209 converter = getattr(Converters, conv_name, None) 210 if converter is None: 211 print "WARNING: cannot find converter %s" % conv_name 212 continue 213 row[key] = converter(row[key]) 214 writer.writerow(row) 215 216 print "Output written to %s" % OUTPUT_FILE 187 def main(): 188 reader = csv.DictReader(open(INPUT_FILE, 'rb')) 189 writer = None 190 191 for num, row in enumerate(reader): 192 if num == 0: 193 writer = csv.DictWriter(open(OUTPUT_FILE, 'wb'), reader.fieldnames) 194 print "FIELDS: " 195 for x, y in enumerate(reader.fieldnames): 196 print x, y 197 header = convert_fieldnames(reader.fieldnames) 198 writer.writerow(header) 199 for key, value in row.items(): 200 if not key in OPTIONS.keys(): 201 continue 202 conv_name = OPTIONS[key] 203 converter = getattr(Converters, conv_name, None) 204 if converter is None: 205 print "WARNING: cannot find converter %s" % conv_name 206 continue 207 row[key] = converter(row[key]) 208 writer.writerow(row) 209 210 print "Output written to %s" % OUTPUT_FILE 211 212 213 if __name__ == '__main__': 214 if len(sys.argv) != 2: 215 print 'Usage: %s <filename>' % __file__ 216 sys.exit(1) 217 main()
Note: See TracChangeset for help on using the changeset viewer.