Changeset 7516
- Timestamp:
- 26 Jan 2012, 09:38:22 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/tools/fix_import_file.py
r7514 r7516 53 53 'current_session': 'session', 54 54 } 55 56 # Mapping input file colnames --> output file colnames 57 COLNAME_MAPPING = { 58 'jamb_reg_no': 'reg_no', 59 'birthday': 'date_of_birth', 60 } 55 61 ## 56 62 ## END OF CONFIG … … 61 67 import sys 62 68 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 69 def 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 72 77 return header 73 78 … … 89 94 else: 90 95 return 9999 91 92 @classmethod93 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 value103 96 104 97 @classmethod … … 166 159 for x, y in enumerate(reader.fieldnames): 167 160 print x, y 168 header = convert_fieldnames(reader )161 header = convert_fieldnames(reader.fieldnames) 169 162 writer.writerow(header) 170 163 for key, value in row.items():
Note: See TracChangeset for help on using the changeset viewer.