Changeset 7514
- Timestamp:
- 26 Jan 2012, 07:29:26 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/tools/fix_import_file.py
r7512 r7514 49 49 'birthday': 'date', 50 50 'request_date': 'datetime', 51 'marit_stat': 'marit_stat', 52 'entry_session': 'session', 53 'current_session': 'session', 51 54 } 52 55 ## … … 58 61 import sys 59 62 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 72 return header 73 60 74 class Converters(): 61 75 """Converters to turn old-style values into new ones. 62 76 """ 63 77 @classmethod 78 def session(self, value): 79 """ '08' --> '2008' 80 """ 81 try: 82 number = int(value) 83 except ValueError: 84 return 9999 85 if number < 14: 86 return number + 2000 87 elif number in range(2000,2015): 88 return number 89 else: 90 return 9999 91 92 @classmethod 64 93 def gender(self, value): 65 """ 'True'/'False' --> 'female'/'male'/'' 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 103 104 @classmethod 105 def marit_stat(self, value): 106 """ 'True'/'False' --> 'married'/'unmarried' 107 """ 108 if value == 'True': 109 value = 'married' 110 elif value == 'False': 111 value = 'unmarried' 112 else: 113 value = '' 114 return value 115 116 @classmethod 117 def gender(self, value): 118 """ 'True'/'False' --> 'female'/'male' 66 119 """ 67 120 if value == 'True': … … 83 136 else: 84 137 value = value.replace('/', '-') 138 # We add the hash symbol to avoid automatic date transformation 139 # in Excel and Calc for further processing 140 value += '#' 85 141 return value 86 142 … … 110 166 for x, y in enumerate(reader.fieldnames): 111 167 print x, y 112 header = dict([(x, x) for x in reader.fieldnames])168 header = convert_fieldnames(reader) 113 169 writer.writerow(header) 114 170 for key, value in row.items():
Note: See TracChangeset for help on using the changeset viewer.