Changeset 7573 for main/waeup.sirp/trunk/tools
- Timestamp:
- 2 Feb 2012, 22:49:54 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/tools/fix_import_file.py
r7572 r7573 29 29 into the specified output file. 30 30 """ 31 import csv 32 import datetime 33 import sys 31 34 32 35 ## 33 36 ## CONFIGURATION SECTION 34 37 ## 35 # file with input data36 INPUT_FILE = '%s' % sys.argv[1]37 38 # file written with modified output39 OUTPUT_FILE = '%s_edited.csv' % sys.argv[1].split('.')[0]40 41 38 # keys are fieldnames in input file, values are methods of class 42 39 # Converter (see below) … … 85 82 ## 86 83 87 import csv88 import datetime89 import sys90 91 84 def convert_fieldnames(fieldnames): 92 85 """Replace input fieldnames by fieldnames of COLNAME_MAPPING. … … 186 179 187 180 def main(): 188 reader = csv.DictReader(open(INPUT_FILE, 'rb')) 181 input_file = '%s' % sys.argv[1] 182 output_file = '%s_edited.csv' % sys.argv[1].split('.')[0] 183 reader = csv.DictReader(open(input_file, 'rb')) 189 184 writer = None 190 185 191 186 for num, row in enumerate(reader): 192 187 if num == 0: 193 writer = csv.DictWriter(open( OUTPUT_FILE, 'wb'), reader.fieldnames)188 writer = csv.DictWriter(open(output_file, 'wb'), reader.fieldnames) 194 189 print "FIELDS: " 195 190 for x, y in enumerate(reader.fieldnames): … … 197 192 header = convert_fieldnames(reader.fieldnames) 198 193 writer.writerow(header) 194 print row['phone'] 199 195 for key, value in row.items(): 200 196 if not key in OPTIONS.keys(): … … 208 204 writer.writerow(row) 209 205 210 print "Output written to %s" % OUTPUT_FILE206 print "Output written to %s" % output_file 211 207 212 208
Note: See TracChangeset for help on using the changeset viewer.