Created
August 23, 2013 10:29
-
-
Save ViktorStiskala/6317817 to your computer and use it in GitHub Desktop.
Convert account number to IBAN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _convert_to_iban(self, account): | |
""" | |
Convert czech account number to IBAN | |
""" | |
acc = self.RE_ACCOUNT.match(account) | |
iban = 'CZ00{b}{ba:0>6}{a:0>10}'.format( | |
ba=acc.group('ba') or 0, | |
a=acc.group('a'), | |
b=acc.group('b'), | |
) | |
# convert IBAN letters into numbers | |
crc = re.sub(r'[A-Z]', lambda m: str(ord(m.group(0)) - 55), iban[4:] + iban[:4]) | |
# compute control digits | |
digits = "{:0>2}".format(98 - int(crc) % 97) | |
return iban[:2] + digits + iban[4:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice