From 153f9f38cc9cf4a1644dd58108d32a7834071bd2 Mon Sep 17 00:00:00 2001 From: Terrtia Date: Fri, 27 Jul 2018 10:20:03 +0200 Subject: [PATCH] chg: [BankAccount] regex --- bin/BankAccount.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/bin/BankAccount.py b/bin/BankAccount.py index f2619cb6..f8c057c3 100755 --- a/bin/BankAccount.py +++ b/bin/BankAccount.py @@ -2,12 +2,12 @@ # -*-coding:UTF-8 -* """ -The ApiKey Module +The BankAccount Module ====================== This module is consuming the Redis-list created by the Categ module. -It apply API_key regexes on paste content and warn if above a threshold. +It apply BankAccount regexes on paste content and warn if above a threshold. """ @@ -15,6 +15,7 @@ import redis import time import re import string +from itertools import chain from packages import Paste from pubsublogger import publisher @@ -31,15 +32,19 @@ def timeout_handler(signum, frame): signal.signal(signal.SIGALRM, timeout_handler) -LETTERS_IBAN = {ord(d): str(i) for i, d in enumerate(string.digits + string.ascii_uppercase)} +#LETTERS_IBAN = {ord(d): str(i) for i, d in enumerate(string.digits + string.ascii_uppercase)} +_LETTERS_IBAN = chain(enumerate(string.digits + string.ascii_uppercase), + enumerate(string.ascii_lowercase, 10)) +LETTERS_IBAN = {ord(d): str(i) for i, d in _LETTERS_IBAN} def iban_number(iban): - return (iban[4:] + iban[:4].translate(LETTERS_IBAN)) + return (iban[4:] + iban[:4]).translate(LETTERS_IBAN) def is_valid_iban(iban): - iban = iban.replace(' ', '') iban_numb = iban_number(iban) iban_numb_check = iban_number(iban[:2] + '00' + iban[4:]) + print(iban_numb) + print(iban_numb_check) check_digit = '{:0>2}'.format(98 - (int(iban_numb_check) % 97)) if check_digit == iban[2:4] and int(iban_numb) % 97 == 1: # valid iban @@ -51,10 +56,16 @@ def is_valid_iban(iban): def check_all_iban(l_iban, paste, filename): nb_valid_iban = 0 for iban in l_iban: - print('checking '+iban) - if is_valid_iban(iban): - print('------') - nb_valid_iban = nb_valid_iban + 1 + iban = iban[0]+iban[1]+iban[2] + iban = ''.join(e for e in iban if e.isalnum()) + #iban = iban.upper() + res = iban_regex_verify.findall(iban) + if res: + print('checking '+iban) + if is_valid_iban(iban): + print('------') + nb_valid_iban = nb_valid_iban + 1 + if(nb_valid_iban > 0): to_print = 'Iban;{};{};{};'.format(paste.p_source, paste.p_date, paste.p_name) publisher.warning('{}Checked found {} IBAN;{}'.format( @@ -78,7 +89,10 @@ if __name__ == "__main__": message = p.get_from_set() - iban_regex = re.compile(r'\b[A-Za-z]{2}[0-9]{2}(?:[ ]?[0-9]{4}){4}(?:[ ]?[0-9]{1,2})?\b') + #iban_regex = re.compile(r'\b[A-Za-z]{2}[0-9]{2}(?:[ ]?[0-9]{4}){4}(?:[ ]?[0-9]{1,2})?\b') + iban_regex = re.compile(r'\b([A-Za-z]{2}[ \-]?[0-9]{2})(?=(?:[ \-]?[A-Za-z0-9]){9,30})((?:[ \-]?[A-Za-z0-9]{3,5}){2,6})([ \-]?[A-Za-z0-9]{1,3})\b') + iban_regex_verify = re.compile(r'^([A-Z]{2})([0-9]{2})([A-Z0-9]{9,30})$') + while True: @@ -103,5 +117,5 @@ if __name__ == "__main__": check_all_iban(l_iban, paste, filename) else: - publisher.debug("Script ApiKey is Idling 10s") + publisher.debug("Script BankAccount is Idling 10s") time.sleep(10)