Skip to content

Instantly share code, notes, and snippets.

@ViktorStiskala
Created August 23, 2013 10:29
Show Gist options
  • Select an option

  • Save ViktorStiskala/6317817 to your computer and use it in GitHub Desktop.

Select an option

Save ViktorStiskala/6317817 to your computer and use it in GitHub Desktop.

Revisions

  1. ViktorStiskala created this gist Aug 23, 2013.
    18 changes: 18 additions & 0 deletions spayd.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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:]