Skip to content

Instantly share code, notes, and snippets.

@ViktorStiskala
Created August 23, 2013 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ViktorStiskala/6317817 to your computer and use it in GitHub Desktop.
Save ViktorStiskala/6317817 to your computer and use it in GitHub Desktop.
Convert account number to IBAN
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:]
@honzajavorek
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment