# from datetime import datetime import re import datetime # import os # import difflib # import csv # import keyring # from envelopes import Envelope from winmentor import WinMentor def find_line_number(csv_file_path, search_string): with open(csv_file_path, 'r', encoding='utf-8') as file: for line_num, line in enumerate(file, 1): if search_string in line: line_number = line_num break return line_number def remove_indentations(file_path): with open(file_path, 'r') as file: lines = file.readlines() # Remove leading spaces or tabs from each line lines = [line.lstrip() for line in lines] with open(file_path, 'w') as file: file.writelines(lines) def get_last_month(day): today = datetime.date.today() first_day_of_this_month = datetime.date(today.year, today.month, 1) last_day_of_last_month = first_day_of_this_month - datetime.timedelta(days=day) # last_month = last_day_of_last_month.strftime('%B %Y') last_month = last_day_of_last_month.month return last_month def get_partners(firm): mentor = WinMentor() part_dict = mentor._get_parts(firm) return part_dict def dig_it(search_in, default=0.00, fl_point=100, pattern=r'\d+') -> float: if isinstance(search_in, (float, int)): return search_in elif ',' not in search_in and '.' not in search_in: try: return int(search_in) except ValueError: pass else: if ',' in search_in[-2:] or '.' in search_in[-2:]: search_in += '0' try: if search_in[0] == '-': res = int(''.join(re.findall(pattern, search_in))[:-2]) + int(''.join(re.findall(pattern, search_in))[-2:]) / fl_point return -res else: res = int(''.join(re.findall(pattern, search_in))[:-2]) + int(''.join(re.findall(pattern, search_in))[-2:]) / fl_point return res except ValueError: return default def re_check(string, pattern=r'(?<=;)[A-Za-z-]*\w [A-Za-z :.-]*(?=;)'): # string = re.sub(r'^[^a-zA-Z]+', '', string) matches = re.findall(pattern, string, flags=re.RegexFlag.IGNORECASE) if string.startswith('Incasare') or string.startswith('Plata'): first_semicolon_index_from_end = string.rfind(';') second_semicolon_index_from_end = string.rfind(';', 0, first_semicolon_index_from_end) third_semicolon_index_from_end = string.rfind(';', 0, second_semicolon_index_from_end) ret_val = string[third_semicolon_index_from_end + 1:second_semicolon_index_from_end] return ret_val elif len(matches) == 0: ret_val = '' return ret_val # matches = re.findall(r'\d+([A-Za-z-]+\s[A-Za-z :.-]*)', string) # if len(matches) == 0: # ret_val = '' # return ret_val # else: # ret_val = matches[0] # return ret_val elif len(matches) > 1: ret_val = matches[1] return ret_val else: ret_val = matches[0] return ret_val def re_check_otp(string, pattern=r'(?<=Ben: )[A-Za-z-]*\w [A-Za-z :.-]*(?= - )'): matches = re.findall(pattern, string, flags=re.RegexFlag.IGNORECASE) if len(matches) == 0: ret_val = '' return ret_val elif len(matches) > 1: ret_val = matches[1] return ret_val else: ret_val = matches[0] return ret_val def re_check_rncb(string, pattern=r'(?<=Beneficiar: )[A-Za-z-]*\w [A-Za-z :.-]*(?=;)|(?<=Platitor: )[A-Za-z-]*\w [A-Za-z :.-]*(?=;)'): matches = re.findall(pattern, string, flags=re.RegexFlag.IGNORECASE) # print(matches) if len(matches) == 0: ret_val = '' return ret_val # elif len(matches) > 1: # ret_val = matches[1] # return ret_val else: ret_val = matches[0] return ret_val if __name__ == '__main__': # s = 'Tranzactie efectuata prin George Banking BCR Referinta 230529S522316437, data valutei 29-05-2023, Decontare -Platitor: CHRYSOPEEA BRANDING & DESIGN SRL; RO60RNCB0106026590140001; CODFISC 6340770; BCR CLUJ CLUJ-NAPOCA-Beneficiar: BUGETUL DE STAT; RO14TREZ2165503XXXXXXXXX; CODFISC 6340770-Detalii: Bugetul de Stat Bugetele Asig. Soc si Fd Spec pt salarii pe luna Apr 2023' # r = re_check_rncb(s) # print(r) line = find_line_number('../csv/RO23BTRL01301202A93957XX-01.08.2023-31.08.2023.csv', 'Rezultat cautare') print(line) # print(get_last_month()) # for i in get_partners(): # print(i) # print(diff_checker(s, check_list))