Changeset 7573


Ignore:
Timestamp:
2 Feb 2012, 22:49:54 (13 years ago)
Author:
uli
Message:

As some constants (input, output-path) are not really constants any
more, we can treat them like usual vars and remove them from config
section.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/tools/fix_import_file.py

    r7572 r7573  
    2929into the specified output file.
    3030"""
     31import csv
     32import datetime
     33import sys
    3134
    3235##
    3336## CONFIGURATION SECTION
    3437##
    35 # file with input data
    36 INPUT_FILE = '%s' % sys.argv[1]
    37 
    38 # file written with modified output
    39 OUTPUT_FILE = '%s_edited.csv' % sys.argv[1].split('.')[0]
    40 
    4138# keys are fieldnames in input file, values are methods of class
    4239# Converter (see below)
     
    8582##
    8683
    87 import csv
    88 import datetime
    89 import sys
    90 
    9184def convert_fieldnames(fieldnames):
    9285    """Replace input fieldnames by fieldnames of COLNAME_MAPPING.
     
    186179
    187180def 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'))
    189184    writer = None
    190185
    191186    for num, row in enumerate(reader):
    192187        if num == 0:
    193             writer = csv.DictWriter(open(OUTPUT_FILE, 'wb'), reader.fieldnames)
     188            writer = csv.DictWriter(open(output_file, 'wb'), reader.fieldnames)
    194189            print "FIELDS: "
    195190            for x, y in enumerate(reader.fieldnames):
     
    197192            header = convert_fieldnames(reader.fieldnames)
    198193            writer.writerow(header)
     194        print row['phone']
    199195        for key, value in row.items():
    200196            if not key in OPTIONS.keys():
     
    208204        writer.writerow(row)
    209205
    210     print "Output written to %s" % OUTPUT_FILE
     206    print "Output written to %s" % output_file
    211207
    212208
Note: See TracChangeset for help on using the changeset viewer.