LEFT | RIGHT |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 # | 3 # |
4 # Copyright (c) 2013-2016, Cédric Krier | 4 # Copyright (c) 2013-2016, Cédric Krier |
5 # Copyright (c) 2014-2015, Nicolas Évrard | 5 # Copyright (c) 2014-2015, Nicolas Évrard |
6 # Copyright (c) 2013-2016, B2CK | 6 # Copyright (c) 2013-2016, B2CK |
7 # All rights reserved. | 7 # All rights reserved. |
8 # | 8 # |
9 # Redistribution and use in source and binary forms, with or without | 9 # Redistribution and use in source and binary forms, with or without |
10 # modification, are permitted provided that the following conditions are met: | 10 # modification, are permitted provided that the following conditions are met: |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 Transaction = namedtuple('Transaction', ['date', 'booking', 'amount', 'id', | 166 Transaction = namedtuple('Transaction', ['date', 'booking', 'amount', 'id', |
167 'reference', 'institution_reference', 'additional_data', | 167 'reference', 'institution_reference', 'additional_data', |
168 'description']) | 168 'description']) |
169 | 169 |
170 | 170 |
171 def _find_swift_tags(tags, description): | 171 def _find_swift_tags(tags, description): |
172 values = {} | 172 values = {} |
173 for tag, name in tags: | 173 for tag, name in tags: |
174 if description.startswith(tag): | 174 if description.startswith(tag): |
175 description = description[len(tag):] | 175 description = description[len(tag):] |
176 next_tag_index = len(description) | 176 cursor = len(description) |
177 for next_tag, _ in tags: | 177 for next_tag, _ in tags: |
178 if next_tag in values or next_tag == tag: | 178 if next_tag in values or next_tag == tag: |
179 continue | 179 continue |
180 index = description.find(next_tag) | 180 index = description.find(next_tag) |
181 if index == -1: | 181 if index == -1: |
182 continue | 182 continue |
183 next_tag_index = min(next_tag_index, index) | 183 cursor = min(cursor, index) |
| 184 next_tag_index = cursor |
184 values[name] = description[:next_tag_index] | 185 values[name] = description[:next_tag_index] |
185 description = description[next_tag_index:] | 186 description = description[next_tag_index:] |
186 if not description: | 187 if not description: |
187 break | 188 break |
188 return values | 189 return values |
189 | 190 |
190 RABO_TAGS = [ | 191 RABO_TAGS = [ |
191 ('/MARF/', 'marf'), | 192 ('/MARF/', 'marf'), |
192 ('/EREF/', 'eref'), | 193 ('/EREF/', 'eref'), |
193 ('/PREF/', 'pref'), | 194 ('/PREF/', 'pref'), |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 values['account_number'], values['name'] = first.split(' ', 1) | 299 values['account_number'], values['name'] = first.split(' ', 1) |
299 except ValueError: | 300 except ValueError: |
300 return {} | 301 return {} |
301 values['address'] = second # XXX Not clear how to split it | 302 values['address'] = second # XXX Not clear how to split it |
302 if third.startswith('aan %s' % values['name']): | 303 if third.startswith('aan %s' % values['name']): |
303 _, values['iban'], values['remittance_info'], values['description'] = \ | 304 _, values['iban'], values['remittance_info'], values['description'] = \ |
304 third.split(',') | 305 third.split(',') |
305 else: | 306 else: |
306 values['reference'] = third | 307 values['reference'] = third |
307 return values | 308 return values |
LEFT | RIGHT |