Changeset 7516


Ignore:
Timestamp:
26 Jan 2012, 09:38:22 (13 years ago)
Author:
uli
Message:
  • Make col names a configuration setting.
  • Remove doubled gender converter.
File:
1 edited

Legend:

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

    r7514 r7516  
    5353    'current_session': 'session',
    5454    }
     55
     56# Mapping input file colnames --> output file colnames
     57COLNAME_MAPPING = {
     58    'jamb_reg_no': 'reg_no',
     59    'birthday': 'date_of_birth',
     60    }
    5561##
    5662## END OF CONFIG
     
    6167import sys
    6268
    63 def convert_fieldnames(reader):
    64     header = {}
    65     for x in reader.fieldnames:
    66         if x == 'jamb_reg_no':
    67             header['jamb_reg_no'] = 'reg_no'
    68         elif x == 'birthday':
    69             header['birthday'] = 'date_of_birth'
    70         else:
    71             header[x] = x
     69def convert_fieldnames(fieldnames):
     70    """Replace input fieldnames by fieldnames of COLNAME_MAPPING.
     71    """
     72    header = dict([(name, name) for name in fieldnames])
     73    for in_name, out_name in COLNAME_MAPPING.items():
     74        if in_name not in header:
     75            continue
     76        header[in_name] = out_name
    7277    return header
    7378
     
    8994        else:
    9095            return 9999
    91 
    92     @classmethod
    93     def gender(self, value):
    94         """ 'True'/'False' --> 'female'/'male'
    95         """
    96         if value == 'True':
    97             value = 'female'
    98         elif value == 'False':
    99             value = 'male'
    100         else:
    101             value = ''
    102         return value
    10396
    10497    @classmethod
     
    166159        for x, y in enumerate(reader.fieldnames):
    167160            print x, y
    168         header = convert_fieldnames(reader)
     161        header = convert_fieldnames(reader.fieldnames)
    169162        writer.writerow(header)
    170163    for key, value in row.items():
Note: See TracChangeset for help on using the changeset viewer.