chg: [BankAccount] regex

pull/232/head
Terrtia 2018-07-27 10:20:03 +02:00
parent 57b631233b
commit 153f9f38cc
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
1 changed files with 25 additions and 11 deletions

View File

@ -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)