|
import logging |
|
|
|
def setup_logger(): |
|
|
|
logger = logging.getLogger('remittance_processing') |
|
logger.setLevel(logging.DEBUG) |
|
|
|
|
|
c_handler = logging.StreamHandler() |
|
f_handler = logging.FileHandler('remittance_processing.log') |
|
c_handler.setLevel(logging.INFO) |
|
f_handler.setLevel(logging.DEBUG) |
|
|
|
|
|
log_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') |
|
c_handler.setFormatter(log_format) |
|
f_handler.setFormatter(log_format) |
|
|
|
|
|
logger.addHandler(c_handler) |
|
logger.addHandler(f_handler) |
|
|
|
return logger |
|
|
|
remittance_logger = setup_logger() |
|
|
|
def remove_duplicate_lists(lists): |
|
""" |
|
Remove duplicate lists from a list of lists. |
|
Args: |
|
lists: |
|
a list of lists of strings |
|
Returns: |
|
a list of lists of strings, where each list is unique |
|
""" |
|
seen = set() |
|
unique_lists = [] |
|
|
|
for lst in lists: |
|
sorted_list = tuple(sorted(lst)) |
|
if sorted_list not in seen: |
|
seen.add(sorted_list) |
|
unique_lists.append(lst) |
|
|
|
return unique_lists |
|
|
|
|
|
import re |
|
from decimal import Decimal, ROUND_HALF_UP |
|
|
|
def format_amount_str_to_decimal(amount_str: str) -> str: |
|
def standardize_number(s): |
|
|
|
last_separator_index = max(s.rfind(','), s.rfind('.')) |
|
if last_separator_index != -1: |
|
|
|
before_separator = s[:last_separator_index] |
|
after_separator = s[last_separator_index+1:] |
|
|
|
|
|
before_separator_cleaned = re.sub(r'[.,\s]', '', before_separator) |
|
|
|
|
|
standardized_s = before_separator_cleaned + '.' + after_separator |
|
else: |
|
|
|
standardized_s = re.sub(r'[.,\s]', '', s) |
|
|
|
return standardized_s |
|
|
|
def remove_chars_after_last_digit(s): |
|
|
|
return re.sub(r'(?<=\d)[^\d]*$', '', s) |
|
|
|
def clean_text(s): |
|
|
|
|
|
|
|
|
|
cleaned_s = re.sub(r'[^\d-]*\s?(\S*\d\S*)', r'\1', s) |
|
return cleaned_s |
|
|
|
|
|
cleaned_amount = clean_text(remove_chars_after_last_digit(standardize_number(amount_str.strip().lower()))) |
|
|
|
|
|
try: |
|
decimal_amount = Decimal(cleaned_amount).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP) |
|
return f"{decimal_amount:.2f}" |
|
except: |
|
|
|
return cleaned_amount |
|
|