{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "insert_query = \"INSERT IGNORE INTO default.TRANSACTION (ID, TDATE, ACCOUNT_ID, MEMO, COUNTRY, OUTFLOW, INFLOW, OWNER_ID, INSTALLMENT_NR, INSTALLMENT_TT, CREATED, UPDATED) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s )\"" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def find_owner(queried_name: str):\n", " from mysql.connector import connect, Error\n", "\n", " query = \"SELECT * FROM OWNER\"\n", " result = []\n", "\n", " try:\n", " with connect(\n", " host=\"127.0.0.1\",\n", " user=\"root\",\n", " password=\"pleasehashapasswordomg\",\n", " database=\"default\",\n", " ) as connection:\n", " # print(\"CONNECTED!\", connection)\n", " with connection.cursor() as cursor:\n", " cursor.execute(query)\n", " query_result = cursor.fetchall()\n", "\n", " for item in query_result:\n", " if item[1].lower() == queried_name:\n", " result.append(item[0])\n", " result.append(item[1])\n", " # print(result)\n", " # print(\"DONE!\")\n", " except Error as e:\n", " print(e)\n", " finally:\n", " connection.close()\n", "\n", " return result if result else None\n", " \n", "find_owner(\"daniel\")[0]" ] }, { "cell_type": "code", "execution_count": 54, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", " SISBB - Sistema de Informações Banco do Brasil \n", "\n", "13/11/2024 Auto-Atendimento 08:44:59\n", "\n", " Fatura do Cartão de Crédito \n", "\n", " \n", "\n", " \n", "\n", "Cliente : DANIEL O CARVALHO \n", "\n", "Nr.Cartão : 4984.****.****.5727 \n", "\n", "Modalidade : OUROCARD VISA INFINITE \n", "\n", " \n", "\n", "Vencimento : 25.04.2024 \n", "\n", "Total da fatura : R$ 18.362,96 \n", "\n", "Pagamento mínimo: R$ 2.754,44 \n", "\n", " \n", "\n", "DEMONSTRATIVO\n", "\n", "--------------------------------------------------------------------------------\n", "\n", "Data Transações País Valor R$ Valor US$\n", "\n", "--------------------------------------------------------------------------------\n", "\n", " \n", "\n", " \n", "\n", " 1 - DANIEL O CARVALHO \n", "\n", "DANIEL\n", "DANIEL\n", "1\n", " \n", "\n", " SALDO FATURA ANTERIOR BR 19.249,92 0,00\n", "\n", " \n", "\n", " \n", "\n", " Pagamentos/Créditos \n", "\n", "25.03.2024PGTO DEBITO CONTA 8611 000006025 200211 -19.249,92 0,00\n", "\n", " \n", "\n", " \n", "\n", " Lazer \n", "\n", "14.03.2024EBN*XSOLLA CURITIBA BR 27,09 0,00\n", "\n", "06.04.2024PAG*MmCultura BRASILIA BR 26,00 0,00\n", "\n", " \n", "\n", " \n", "\n", " Restaurantes \n", "\n", "16.03.2024IFD*MARIANA PERDOMO CONBRASILIA BR 80,79 0,00\n", "\n", "16.03.2024IFD*iFood OSASCO BR 5,00 0,00\n", "\n", "17.03.2024IFD*TT BRASILIA COMERCIBRASILIA BR 134,00 0,00\n", "\n", "18.03.2024IFD*IFOOD.COM AGENCIA DOsasco BR 12,90 0,00\n", "\n", "19.03.2024CASA ALMERIA BRASILIA BR 157,92 0,00\n", "\n", "19.03.2024CASA ALMERIA BRASILIA BR 105,00 0,00\n", "\n", "19.03.2024IFD*TAIKAN FAST SUSHI LBRASILIA BR 149,90 0,00\n", "\n", "19.03.2024IFD*iFood OSASCO BR 10,00 0,00\n", "\n", "28.03.2024FOGO E BRASA STEAK HOUSPIRENOPOLIS BR 238,00 0,00\n", "\n", "03.04.2024ifood *IFD*RC MELO C Vila Yara Osa BR 226,51 0,00\n", "\n", "04.04.2024IFD*TAIKAN FAST SUSHI LBRASILIA BR 149,90 0,00\n", "\n", "06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 220,00 0,00\n", "\n", "06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 4,00 0,00\n", "\n", "06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 16,00 0,00\n", "\n", "06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 12,00 0,00\n", "\n", "06.04.2024IFD*ME COMERCIO DE ALIMBRASILIA BR 66,90 0,00\n", "\n", "07.04.2024IFD*UPTOWN BURGERS E SHBRASILIA BR 76,70 0,00\n", "\n", " \n", "\n", " \n", "\n", " Saúde \n", "\n", "20.03.2024DROGASIL 2067 BRASILIA BR 516,80 0,00\n", "\n", "20.03.2024REDE BRASIL DRUGSTORE BRASILIA BR 512,73 0,00\n", "\n", "20.03.2024PAGUE MENOS 1225 BRASILIA BR 568,23 0,00\n", "\n", "05.04.2024DROGARIA SAO PAULO BRASILIA BR 248,37 0,00\n", "\n", " \n", "\n", " \n", "\n", " Serviços \n", "\n", "15.03.2024VELOE BARUERI BR 22,26 0,00\n", "\n", "18.03.2024NETFLIX.COM SAO PAULO BR 39,90 0,00\n", "\n", "19.03.2024PAG*FolhaDeSPaulo SAO PAULO BR 29,90 0,00\n", "\n", "23.03.2024PAG*Zig SAO PAULO BR 376,01 0,00\n", "\n", "27.03.2024Gympass GympassBr Sao Paulo BR 399,90 0,00\n", "\n", "29.03.2024MP *MELIMAIS OSASCO BR 17,99 0,00\n", "\n", "01.04.2024MERCADOLIVRE*AGUSHOPCOMOSASCO BR 39,90 0,00\n", "\n", "01.04.2024MERCADOLIVRE*GIGATUDOBYOSASCO BR 418,41 0,00\n", "\n", "02.04.2024MERCADOLIVRE*BRASIL OSASCO BR 58,57 0,00\n", "\n", "03.04.2024MERCADOLIVRE*AGUSHOPCOMOSASCO BR 31,90 0,00\n", "\n", "04.04.2024IFD*Gleidson Renato LeiOsasco BR 10,00 0,00\n", "\n", "04.04.2024APPLE.COM/BILL SAO PAULO BR 54,90 0,00\n", "\n", "05.04.2024MERCADOLIVRE*WIXACESSOROSASCO BR 58,57 0,00\n", "\n", "04.04.2024IFD*LOG CITY ESPRESS Osasco BR 5,00 0,00\n", "\n", "05.04.2024Gympass GympassBr Sao Paulo BR 399,90 0,00\n", "\n", "05.04.2024MR JOHN BARBEARIA LTDA BRASILIA BR 60,00 0,00\n", "\n", "09.04.2024MERCADOLIVRE*SABORESDAMOSASCO BR 109,90 0,00\n", "\n", " \n", "\n", " \n", "\n", " Supermercados \n", "\n", "24.03.2024PAG*GaleteriaSerrana BRASILIA BR 164,78 0,00\n", "\n", " \n", "\n", " \n", "\n", " Transporte \n", "\n", "18.03.2024UBER* TRIP OSASCO BR 13,98 0,00\n", "\n", "18.03.2024UBER *TRIP HELP.UBER.COSAO PAULO BR 1,60 0,00\n", "\n", "18.03.2024UBER * PENDING SAO PAULO BR 13,92 0,00\n", "\n", "18.03.2024UBER *TRIP HELP.UBER.COSAO PAULO BR 5,00 0,00\n", "\n", "19.03.2024UBER* TRIP OSASCO BR 11,83 0,00\n", "\n", "21.03.2024UBER * PENDING SAO PAULO BR 10,98 0,00\n", "\n", "23.03.2024UBER * PENDING SAO PAULO BR 10,96 0,00\n", "\n", "25.03.2024UBER* TRIP OSASCO BR 14,55 0,00\n", "\n", "25.03.2024UBER* TRIP OSASCO BR 5,00 0,00\n", "\n", "25.03.2024UBER *TRIP HELP.UBER.COSAO PAULO BR 14,80 0,00\n", "\n", "25.03.2024UBER * PENDING SAO PAULO BR 13,92 0,00\n", "\n", "25.03.2024UBER *TRIP HELP.UBER.COSAO PAULO BR 3,41 0,00\n", "\n", "28.03.2024UBER* TRIP OSASCO BR 14,31 0,00\n", "\n", "28.03.2024UBER* TRIP OSASCO BR 1,44 0,00\n", "\n", "28.03.2024UBER* TRIP OSASCO BR 14,08 0,00\n", "\n", "28.03.2024UBER* TRIP OSASCO BR 3,00 0,00\n", "\n", "02.04.2024UBER * PENDING SAO PAULO BR 19,94 0,00\n", "\n", "02.04.2024UBER * PENDING SAO PAULO BR 39,93 0,00\n", "\n", "04.04.2024UBER * PENDING SAO PAULO BR 10,93 0,00\n", "\n", "06.04.2024UBER * PENDING SAO PAULO BR 39,94 0,00\n", "\n", "09.04.2024UBER * PENDING SAO PAULO BR 10,97 0,00\n", "\n", " \n", "\n", " \n", "\n", " Vestuário \n", "\n", "27.03.2024CASA DO CHOCOLATE BRASILIA BR 283,89 0,00\n", "\n", " \n", "\n", " \n", "\n", " Outros lançamentos \n", "\n", "13.03.2024DL*GOOGLE YouTub SAO PAULO BR 41,90 0,00\n", "\n", "18.03.2024Amazon Music SAO PAULO BR 21,90 0,00\n", "\n", "14.03.2024STEAM PURCHASE SEATTLE DE 24,00 0,00\n", "\n", "19.03.2024IOF - COMPRA NO EXTERIOR 1,05 0,00\n", "\n", "15.03.2024STEAM PURCHASE SEATTLE DE 47,88 0,00\n", "\n", "19.03.2024IOF - COMPRA NO EXTERIOR 2,09 0,00\n", "\n", "04.04.2024STEAM PURCHASE SEATTLE DE 117,98 0,00\n", "\n", "08.04.2024IOF - COMPRA NO EXTERIOR 1,29 0,00\n", "\n", " \n", "\n", " \n", "\n", " Compras parceladas \n", "\n", "15.01.2024MP*MUNDODOSCO PARC 03/10 SAO PAULO BR 159,90 0,00\n", "\n", "17.10.2023BIANCHINI AUT PARC 06/10 BRASILIA BR 535,00 0,00\n", "\n", "22.03.2024SNOW PARC 01/02 BELO HORIZONBR 2.466,69 0,00\n", "\n", "26.03.2024QUEST 01/02-SNOW BELO BR -2.466,69 0,00\n", "\n", "22.03.2024SNOW PARC 01/10 BELO HORIZONBR 493,41 0,00\n", "\n", "26.03.2024QUEST 01/10-SNOW BELO BR -493,41 0,00\n", "\n", " \n", "\n", " \n", "\n", " SubTotal 7.373,90 0,00\n", "\n", " \n", "\n", " \n", "\n", " 4 - IZABELY C NORMANDO \n", "\n", "IZABELY\n", "IZABELY\n", "2\n", " \n", "\n", " \n", "\n", " Restaurantes \n", "\n", "18.03.2024FEDERAL GOURMET BRASILIA BR 22,56 0,00\n", "\n", "18.03.2024FEDERAL GOURMET BRASILIA BR 18,85 0,00\n", "\n", "23.03.2024COCO BAMBU IGUATEMI BR BRASILIA BR 250,23 0,00\n", "\n", "30.03.2024PAG*ColoreGelateria PIRENOPOLIS BR 44,46 0,00\n", "\n", "01.04.2024FEDERAL GOUR BRASILIA BR 18,93 0,00\n", "\n", "01.04.2024FEDERAL GOUR BRASILIA BR 120,00 0,00\n", "\n", "06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 27,00 0,00\n", "\n", "06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 16,00 0,00\n", "\n", "07.04.2024ifood *IFD*SN COMERC Vila Yara Osa BR 152,00 0,00\n", "\n", " \n", "\n", " \n", "\n", " Saúde \n", "\n", "18.03.2024LISTO*CLINICAESTETICARNBRASILIA BR 4.300,00 0,00\n", "\n", "28.03.2024DROGASIL 2067 BRASILIA BR 114,34 0,00\n", "\n", "08.04.2024DROGASIL 1383 BRASILIA BR 92,18 0,00\n", "\n", " \n", "\n", " \n", "\n", " Serviços \n", "\n", "13.03.2024CODA OIAPOQUE BR 110,83 0,00\n", "\n", "14.03.2024VINHOS E CO MACAPA BR 177,92 0,00\n", "\n", "15.03.2024RUSTIC ALIMENTOS LTDA MACAPA BR 71,50 0,00\n", "\n", "19.03.2024PICPAY UNICOMPRASINT Brasilia BR 353,00 0,00\n", "\n", "24.03.2024DM *SHEINCOM MIDVIEW CITY BR 162,93 0,00\n", "\n", "26.03.2024MP*DONAFUTRICA OSASCO BR 824,50 0,00\n", "\n", "27.03.2024CAFES PLURAIS TORRADOS BRASILIA BR 279,90 0,00\n", "\n", "30.03.2024PAG*WeniaFerreiraDo PIRENOPOLIS BR 94,80 0,00\n", "\n", "31.03.2024RR PIRENOPOLIS BR 240,08 0,00\n", "\n", "10.04.2024IFD*F C BOLOS DO FLAVIOBRASILIA BR 90,00 0,00\n", "\n", " \n", "\n", " \n", "\n", " Supermercados \n", "\n", "07.04.2024PAG*GaleteriaSerrana BRASILIA BR 174,10 0,00\n", "\n", " \n", "\n", " \n", "\n", " Vestuário \n", "\n", "24.03.2024DL*SHEINCOM SAO PAULO BR 270,94 0,00\n", "\n", "30.03.2024MARIA PIRENOPOLIS BR 120,00 0,00\n", "\n", "08.04.2024TRACKEFIELD BRASILIA BR 120,10 0,00\n", "\n", " \n", "\n", " \n", "\n", " Viagens \n", "\n", "15.03.2024BDH HOTELARIA MACAPA BR 72,00 0,00\n", "\n", " \n", "\n", " \n", "\n", " Outros lançamentos \n", "\n", "14.03.2024LATAM SITE SAO PAULO BR 93,00 0,00\n", "\n", " \n", "\n", " \n", "\n", " Compras parceladas \n", "\n", "15.01.2024LDM PARC 03/04 BRASILIA BR 1.100,00 0,00\n", "\n", "17.01.2024BRASILIA EMPR PARC 03/12 BRASILIA BR 599,00 0,00\n", "\n", "26.01.2024VISAO INSTITU PARC 03/05 BRASILIA BR 200,00 0,00\n", "\n", "26.03.2024BIOEXATA FARM PARC 01/03 BRASILIA BR 583,01 0,00\n", "\n", "07.01.2024PG *B4A GLAMB PARC 04/12 SAO PAULO BR 74,90 0,00\n", "\n", " \n", "\n", " \n", "\n", " SubTotal 10.989,06 0,00\n", "\n", " \n", "\n", " \n", "\n", " Total 18.362,96 0,00\n", "\n", " \n", "\n", " \n", "\n", "RESUMO EM REAL\n", "\n", "--------------------------------------------------------------------------------\n", "\n", " Saldo Pagamento/ Compras/ Total Lim. extra Saldo \n", "\n", " Anterior Créditos Débitos R$ utilizado Atual - R$ \n", "\n", "--------------------------------------------------------------------------------\n", "\n", " 19.249,92 - -22.210,02 + 21.323,06 = 18.362,96 - 0,00 = 18.362,96\n", "\n", "--------------------------------------------------------------------------------\n", "\n", " \n", "\n", "RESUMO EM DÓLAR\n", "\n", "--------------------------------------------------------------------------------\n", "\n", " Compras/ Outros Saldo Taxa de Saldo \n", "\n", " Saques débitos Créditos Atual U$ conversão convertido \n", "\n", "--------------------------------------------------------------------------------\n", "\n", " 0,00 - 0,00 + 0,00 = 0,00 X 0,0000 = 0,00\n", "\n", "--------------------------------------------------------------------------------\n", "\n", " \n", "\n", " \n", "\n", "LIMITES - R$\n", "\n", "--------------------------------------------------------------------------------\n", "\n", "Total para transações à vista : 70.255,00\n", "\n", "Saques : 70.255,00\n", "\n", "(Incluido no total transação à vista)\n", "\n", "Total para transações parceladas : 0,00\n", "\n", "Crediário : 249.337,00\n", "\n", " \n", "\n", " \n", "\n", "ENCARGOS FINANCEIROS - R$ 1 2\n", "\n", "--------------------------------------------------------------------------------\n", "\n", "Crédito Rotativo : 9,94 14,16\n", "\n", "Crédito Parcelado: 3,00 10,21\n", "\n", "Permanência : 1,00 1,00\n", "\n", "Multa : 2,00 2,00\n", "\n", "1. Para o periodo %am \n", "\n", "2. Máximo próximo periodo %am \n", "\n", " \n", "\n", " \n", "\n", "PONTO PRA VOCÊ/LIVELO\n", "\n", "--------------------------------------------------------------------------------\n", "\n", " Pontuação acumulada Até 10.04.2024 : 1.331\n", "\n", "--------------------------------------------------------------------------------\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "Error during Transaction Lists creation\n", "Error checking if list is Partial\n" ] } ], "source": [ "def create_lists(file_name: str):\n", " import re\n", "\n", " # Open the text file\n", " with open(file_name, \"r\", encoding=\"latin\") as file:\n", " # Read the contents of the file\n", " contents = file.readlines()\n", "\n", " # Define the regex patterns\n", " owner_pattern = r\"\\s\\d\\s?-\\s?([A-Z]+)\"\n", " line_pattern = r\"\\d{2}\\.\\d{2}\\.\\d{4}.{23}.{14}.{2}\\s*-?\\d*\\.?\\d+,\\d{2}\\s*\\d+,\\d{2}\"\n", " payment_pattern = (r\"\\d{2}\\.\\d{2}\\.\\d{4}PGTO.*200211(\\s*-?\\d*\\.?\\d+,\\d{2})(\\s*\\d+,\\d{2})\")\n", " partial_invoice_line_pattern = r\"\\d{2}\\/\\d{2}.{27}.{16}.{2}\\s+\\s*-?\\d*\\.?\\d+,\\d{2}\\s*\\d+,\\d{2}\"\n", "\n", " # Lists\n", " current_list = None\n", " owner_list = []\n", " result = {}\n", "\n", " # silly_counter = 1\n", " isPartial = True\n", "\n", " # Find Owners\n", " try:\n", " for line in contents:\n", " # line = line.strip()\n", " print(line)\n", "\n", " found_owners = re.findall(owner_pattern, line)\n", " if found_owners:\n", " for owner_name in found_owners:\n", " print(owner_name)\n", " list_name = f\"list_{owner_name.lower()}\"\n", " owner_list.append(list_name)\n", " result[list_name] = {}\n", " result[list_name][\"owner_name\"] = owner_name\n", " result[list_name][\"owner_id\"] = find_owner(owner_name.lower())[0]\n", " print(result[list_name][\"owner_name\"])\n", " print(result[list_name][\"owner_id\"])\n", " except:\n", " print(\"Error during owner search\")\n", "\n", " # Open the text file\n", " # with open(file_name, \"r\", encoding=\"latin\") as file:\n", " # # Read the contents of the file\n", " # contents = file.readlines()\n", "\n", " # Treat and create transaction lists\n", " try:\n", " for line in contents:\n", " # line = line.strip()\n", " # print(line)\n", "\n", " if re.match(owner_pattern, line):\n", " found_owner = re.match(owner_pattern, line)\n", " print(\"found_owner: \", found_owner.group(1).lower())\n", " owner_list = f\"list_{found_owner.group(1).lower()}\"\n", " current_list = owner_list\n", " result[current_list][\"tlist\"] = []\n", " else:\n", " if re.match(payment_pattern, line):\n", " result[current_list][\"tlist\"].append(line)\n", " elif re.match(line_pattern, line) or re.match(partial_invoice_line_pattern, line):\n", " result[current_list][\"tlist\"].append(line)\n", " except:\n", " print(\"Error during Transaction Lists creation\")\n", "\n", " # Check file pattern\n", " try:\n", " sample = result[current_list][\"tlist\"][0]\n", " if re.match(line_pattern, sample):\n", " isPartial = False\n", "\n", " for listObj in result:\n", " result[listObj][\"isPartial\"] = isPartial\n", "\n", " return result\n", " except:\n", " print(\"Error checking if list is Partial\")\n", "\n", "create_lists(\"./documents/OUROCARD_VISA_INFINITE-Abr_24.txt\")" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error during Transaction Lists creation\n" ] }, { "data": { "text/plain": [ "{}" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "create_lists(\"./documents/OUROCARD_VISA_INFINITE-Abr_24.txt\")" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', ' SISBB - Sistema de Informações Banco do Brasil \\n', '13/11/2024 Auto-Atendimento 08:44:59\\n', ' Fatura do Cartão de Crédito \\n', ' \\n', ' \\n', 'Cliente : DANIEL O CARVALHO \\n', 'Nr.Cartão : 4984.****.****.5727 \\n', 'Modalidade : OUROCARD VISA INFINITE \\n', ' \\n', 'Vencimento : 25.04.2024 \\n', 'Total da fatura : R$ 18.362,96 \\n', 'Pagamento mínimo: R$ 2.754,44 \\n', ' \\n', 'DEMONSTRATIVO\\n', '--------------------------------------------------------------------------------\\n', 'Data Transações País Valor R$ Valor US$\\n', '--------------------------------------------------------------------------------\\n', ' \\n', ' \\n', ' 1 - DANIEL O CARVALHO \\n', ' \\n', ' SALDO FATURA ANTERIOR BR 19.249,92 0,00\\n', ' \\n', ' \\n', ' Pagamentos/Créditos \\n', '25.03.2024PGTO DEBITO CONTA 8611 000006025 200211 -19.249,92 0,00\\n', ' \\n', ' \\n', ' Lazer \\n', '14.03.2024EBN*XSOLLA CURITIBA BR 27,09 0,00\\n', '06.04.2024PAG*MmCultura BRASILIA BR 26,00 0,00\\n', ' \\n', ' \\n', ' Restaurantes \\n', '16.03.2024IFD*MARIANA PERDOMO CONBRASILIA BR 80,79 0,00\\n', '16.03.2024IFD*iFood OSASCO BR 5,00 0,00\\n', '17.03.2024IFD*TT BRASILIA COMERCIBRASILIA BR 134,00 0,00\\n', '18.03.2024IFD*IFOOD.COM AGENCIA DOsasco BR 12,90 0,00\\n', '19.03.2024CASA ALMERIA BRASILIA BR 157,92 0,00\\n', '19.03.2024CASA ALMERIA BRASILIA BR 105,00 0,00\\n', '19.03.2024IFD*TAIKAN FAST SUSHI LBRASILIA BR 149,90 0,00\\n', '19.03.2024IFD*iFood OSASCO BR 10,00 0,00\\n', '28.03.2024FOGO E BRASA STEAK HOUSPIRENOPOLIS BR 238,00 0,00\\n', '03.04.2024ifood *IFD*RC MELO C Vila Yara Osa BR 226,51 0,00\\n', '04.04.2024IFD*TAIKAN FAST SUSHI LBRASILIA BR 149,90 0,00\\n', '06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 220,00 0,00\\n', '06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 4,00 0,00\\n', '06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 16,00 0,00\\n', '06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 12,00 0,00\\n', '06.04.2024IFD*ME COMERCIO DE ALIMBRASILIA BR 66,90 0,00\\n', '07.04.2024IFD*UPTOWN BURGERS E SHBRASILIA BR 76,70 0,00\\n', ' \\n', ' \\n', ' Saúde \\n', '20.03.2024DROGASIL 2067 BRASILIA BR 516,80 0,00\\n', '20.03.2024REDE BRASIL DRUGSTORE BRASILIA BR 512,73 0,00\\n', '20.03.2024PAGUE MENOS 1225 BRASILIA BR 568,23 0,00\\n', '05.04.2024DROGARIA SAO PAULO BRASILIA BR 248,37 0,00\\n', ' \\n', ' \\n', ' Serviços \\n', '15.03.2024VELOE BARUERI BR 22,26 0,00\\n', '18.03.2024NETFLIX.COM SAO PAULO BR 39,90 0,00\\n', '19.03.2024PAG*FolhaDeSPaulo SAO PAULO BR 29,90 0,00\\n', '23.03.2024PAG*Zig SAO PAULO BR 376,01 0,00\\n', '27.03.2024Gympass GympassBr Sao Paulo BR 399,90 0,00\\n', '29.03.2024MP *MELIMAIS OSASCO BR 17,99 0,00\\n', '01.04.2024MERCADOLIVRE*AGUSHOPCOMOSASCO BR 39,90 0,00\\n', '01.04.2024MERCADOLIVRE*GIGATUDOBYOSASCO BR 418,41 0,00\\n', '02.04.2024MERCADOLIVRE*BRASIL OSASCO BR 58,57 0,00\\n', '03.04.2024MERCADOLIVRE*AGUSHOPCOMOSASCO BR 31,90 0,00\\n', '04.04.2024IFD*Gleidson Renato LeiOsasco BR 10,00 0,00\\n', '04.04.2024APPLE.COM/BILL SAO PAULO BR 54,90 0,00\\n', '05.04.2024MERCADOLIVRE*WIXACESSOROSASCO BR 58,57 0,00\\n', '04.04.2024IFD*LOG CITY ESPRESS Osasco BR 5,00 0,00\\n', '05.04.2024Gympass GympassBr Sao Paulo BR 399,90 0,00\\n', '05.04.2024MR JOHN BARBEARIA LTDA BRASILIA BR 60,00 0,00\\n', '09.04.2024MERCADOLIVRE*SABORESDAMOSASCO BR 109,90 0,00\\n', ' \\n', ' \\n', ' Supermercados \\n', '24.03.2024PAG*GaleteriaSerrana BRASILIA BR 164,78 0,00\\n', ' \\n', ' \\n', ' Transporte \\n', '18.03.2024UBER* TRIP OSASCO BR 13,98 0,00\\n', '18.03.2024UBER *TRIP HELP.UBER.COSAO PAULO BR 1,60 0,00\\n', '18.03.2024UBER * PENDING SAO PAULO BR 13,92 0,00\\n', '18.03.2024UBER *TRIP HELP.UBER.COSAO PAULO BR 5,00 0,00\\n', '19.03.2024UBER* TRIP OSASCO BR 11,83 0,00\\n', '21.03.2024UBER * PENDING SAO PAULO BR 10,98 0,00\\n', '23.03.2024UBER * PENDING SAO PAULO BR 10,96 0,00\\n', '25.03.2024UBER* TRIP OSASCO BR 14,55 0,00\\n', '25.03.2024UBER* TRIP OSASCO BR 5,00 0,00\\n', '25.03.2024UBER *TRIP HELP.UBER.COSAO PAULO BR 14,80 0,00\\n', '25.03.2024UBER * PENDING SAO PAULO BR 13,92 0,00\\n', '25.03.2024UBER *TRIP HELP.UBER.COSAO PAULO BR 3,41 0,00\\n', '28.03.2024UBER* TRIP OSASCO BR 14,31 0,00\\n', '28.03.2024UBER* TRIP OSASCO BR 1,44 0,00\\n', '28.03.2024UBER* TRIP OSASCO BR 14,08 0,00\\n', '28.03.2024UBER* TRIP OSASCO BR 3,00 0,00\\n', '02.04.2024UBER * PENDING SAO PAULO BR 19,94 0,00\\n', '02.04.2024UBER * PENDING SAO PAULO BR 39,93 0,00\\n', '04.04.2024UBER * PENDING SAO PAULO BR 10,93 0,00\\n', '06.04.2024UBER * PENDING SAO PAULO BR 39,94 0,00\\n', '09.04.2024UBER * PENDING SAO PAULO BR 10,97 0,00\\n', ' \\n', ' \\n', ' Vestuário \\n', '27.03.2024CASA DO CHOCOLATE BRASILIA BR 283,89 0,00\\n', ' \\n', ' \\n', ' Outros lançamentos \\n', '13.03.2024DL*GOOGLE YouTub SAO PAULO BR 41,90 0,00\\n', '18.03.2024Amazon Music SAO PAULO BR 21,90 0,00\\n', '14.03.2024STEAM PURCHASE SEATTLE DE 24,00 0,00\\n', '19.03.2024IOF - COMPRA NO EXTERIOR 1,05 0,00\\n', '15.03.2024STEAM PURCHASE SEATTLE DE 47,88 0,00\\n', '19.03.2024IOF - COMPRA NO EXTERIOR 2,09 0,00\\n', '04.04.2024STEAM PURCHASE SEATTLE DE 117,98 0,00\\n', '08.04.2024IOF - COMPRA NO EXTERIOR 1,29 0,00\\n', ' \\n', ' \\n', ' Compras parceladas \\n', '15.01.2024MP*MUNDODOSCO PARC 03/10 SAO PAULO BR 159,90 0,00\\n', '17.10.2023BIANCHINI AUT PARC 06/10 BRASILIA BR 535,00 0,00\\n', '22.03.2024SNOW PARC 01/02 BELO HORIZONBR 2.466,69 0,00\\n', '26.03.2024QUEST 01/02-SNOW BELO BR -2.466,69 0,00\\n', '22.03.2024SNOW PARC 01/10 BELO HORIZONBR 493,41 0,00\\n', '26.03.2024QUEST 01/10-SNOW BELO BR -493,41 0,00\\n', ' \\n', ' \\n', ' SubTotal 7.373,90 0,00\\n', ' \\n', ' \\n', ' 4 - IZABELY C NORMANDO \\n', ' \\n', ' \\n', ' Restaurantes \\n', '18.03.2024FEDERAL GOURMET BRASILIA BR 22,56 0,00\\n', '18.03.2024FEDERAL GOURMET BRASILIA BR 18,85 0,00\\n', '23.03.2024COCO BAMBU IGUATEMI BR BRASILIA BR 250,23 0,00\\n', '30.03.2024PAG*ColoreGelateria PIRENOPOLIS BR 44,46 0,00\\n', '01.04.2024FEDERAL GOUR BRASILIA BR 18,93 0,00\\n', '01.04.2024FEDERAL GOUR BRASILIA BR 120,00 0,00\\n', '06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 27,00 0,00\\n', '06.04.2024BAR E RESTAURANTE TIA BRASILIA BR 16,00 0,00\\n', '07.04.2024ifood *IFD*SN COMERC Vila Yara Osa BR 152,00 0,00\\n', ' \\n', ' \\n', ' Saúde \\n', '18.03.2024LISTO*CLINICAESTETICARNBRASILIA BR 4.300,00 0,00\\n', '28.03.2024DROGASIL 2067 BRASILIA BR 114,34 0,00\\n', '08.04.2024DROGASIL 1383 BRASILIA BR 92,18 0,00\\n', ' \\n', ' \\n', ' Serviços \\n', '13.03.2024CODA OIAPOQUE BR 110,83 0,00\\n', '14.03.2024VINHOS E CO MACAPA BR 177,92 0,00\\n', '15.03.2024RUSTIC ALIMENTOS LTDA MACAPA BR 71,50 0,00\\n', '19.03.2024PICPAY UNICOMPRASINT Brasilia BR 353,00 0,00\\n', '24.03.2024DM *SHEINCOM MIDVIEW CITY BR 162,93 0,00\\n', '26.03.2024MP*DONAFUTRICA OSASCO BR 824,50 0,00\\n', '27.03.2024CAFES PLURAIS TORRADOS BRASILIA BR 279,90 0,00\\n', '30.03.2024PAG*WeniaFerreiraDo PIRENOPOLIS BR 94,80 0,00\\n', '31.03.2024RR PIRENOPOLIS BR 240,08 0,00\\n', '10.04.2024IFD*F C BOLOS DO FLAVIOBRASILIA BR 90,00 0,00\\n', ' \\n', ' \\n', ' Supermercados \\n', '07.04.2024PAG*GaleteriaSerrana BRASILIA BR 174,10 0,00\\n', ' \\n', ' \\n', ' Vestuário \\n', '24.03.2024DL*SHEINCOM SAO PAULO BR 270,94 0,00\\n', '30.03.2024MARIA PIRENOPOLIS BR 120,00 0,00\\n', '08.04.2024TRACKEFIELD BRASILIA BR 120,10 0,00\\n', ' \\n', ' \\n', ' Viagens \\n', '15.03.2024BDH HOTELARIA MACAPA BR 72,00 0,00\\n', ' \\n', ' \\n', ' Outros lançamentos \\n', '14.03.2024LATAM SITE SAO PAULO BR 93,00 0,00\\n', ' \\n', ' \\n', ' Compras parceladas \\n', '15.01.2024LDM PARC 03/04 BRASILIA BR 1.100,00 0,00\\n', '17.01.2024BRASILIA EMPR PARC 03/12 BRASILIA BR 599,00 0,00\\n', '26.01.2024VISAO INSTITU PARC 03/05 BRASILIA BR 200,00 0,00\\n', '26.03.2024BIOEXATA FARM PARC 01/03 BRASILIA BR 583,01 0,00\\n', '07.01.2024PG *B4A GLAMB PARC 04/12 SAO PAULO BR 74,90 0,00\\n', ' \\n', ' \\n', ' SubTotal 10.989,06 0,00\\n', ' \\n', ' \\n', ' Total 18.362,96 0,00\\n', ' \\n', ' \\n', 'RESUMO EM REAL\\n', '--------------------------------------------------------------------------------\\n', ' Saldo Pagamento/ Compras/ Total Lim. extra Saldo \\n', ' Anterior Créditos Débitos R$ utilizado Atual - R$ \\n', '--------------------------------------------------------------------------------\\n', ' 19.249,92 - -22.210,02 + 21.323,06 = 18.362,96 - 0,00 = 18.362,96\\n', '--------------------------------------------------------------------------------\\n', ' \\n', 'RESUMO EM DÓLAR\\n', '--------------------------------------------------------------------------------\\n', ' Compras/ Outros Saldo Taxa de Saldo \\n', ' Saques débitos Créditos Atual U$ conversão convertido \\n', '--------------------------------------------------------------------------------\\n', ' 0,00 - 0,00 + 0,00 = 0,00 X 0,0000 = 0,00\\n', '--------------------------------------------------------------------------------\\n', ' \\n', ' \\n', 'LIMITES - R$\\n', '--------------------------------------------------------------------------------\\n', 'Total para transações à vista : 70.255,00\\n', 'Saques : 70.255,00\\n', '(Incluido no total transação à vista)\\n', 'Total para transações parceladas : 0,00\\n', 'Crediário : 249.337,00\\n', ' \\n', ' \\n', 'ENCARGOS FINANCEIROS - R$ 1 2\\n', '--------------------------------------------------------------------------------\\n', 'Crédito Rotativo : 9,94 14,16\\n', 'Crédito Parcelado: 3,00 10,21\\n', 'Permanência : 1,00 1,00\\n', 'Multa : 2,00 2,00\\n', '1. Para o periodo %am \\n', '2. Máximo próximo periodo %am \\n', ' \\n', ' \\n', 'PONTO PRA VOCÊ/LIVELO\\n', '--------------------------------------------------------------------------------\\n', ' Pontuação acumulada Até 10.04.2024 : 1.331\\n', '--------------------------------------------------------------------------------\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n', '\\n']\n" ] } ], "source": [ "# import os\n", "# file = os.path.join(\"E:\\\\forge\\\\python\\\\robopato\\\\documents\", \"OUROCARD_VISA_INFINITE-Mar_24.txt\")\n", "file = \"./documents/OUROCARD_VISA_INFINITE-Abr_24.txt\"\n", "def yadda(file: str):\n", " # Open the text file\n", " with open(file, \"r\", encoding=\"latin\") as file:\n", " # Read the contents of the file\n", " contents = file.readlines()\n", " print(contents)\n", "\n", "yadda(file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def build_insert(input_dict: dict, account: int):\n", " from datetime import date, datetime\n", " from decimal import Decimal\n", " import re\n", " import hashlib\n", "\n", " insert_bulk = []\n", "\n", " # RegEx Patterns\n", " line_group_pattern = r\"(?P\\d{2})\\.(?P\\d{2})\\.(?P\\d{4})(?:(?P.+PARC (?P\\d+.)\\/(?P\\d+)\\s.{12})|(?P.{37}))(?P.{2})(?P\\s*-?\\d*\\.?\\d+,\\d{2})(?P\\s*\\d*\\.?\\d+,\\d{2})\"\n", " partial_invoice_group_pattern = r\"(?P\\d{2})\\/(?P\\d{2})(?:(?P.+PARC (?P\\d{2})\\/(?P\\d{2}).{15})|(?P.{43}))(?P.{2})(?P\\s+\\s*-?\\d*\\.?\\d+,\\d{2})(?P\\s*\\d+,\\d{2})\"\n", " payment_pattern = r\"(?P\\d{2})\\.(?P\\d{2})\\.(?P\\d{4})(?PPGTO DEBITO CONTA).*200211(?P\\s*-?\\d*\\.?\\d+,\\d{2})(?P\\s*\\d+,\\d{2})\"\n", "\n", " for key in input_dict:\n", " if input_dict[key][\"isPartial\"]:\n", " pattern_to_use = partial_invoice_group_pattern\n", " else:\n", " pattern_to_use = line_group_pattern\n", "\n", " for item in input_dict[key][\"tlist\"]:\n", " # check if it is an invoice payment\n", " matches = re.match(payment_pattern, item)\n", " if matches:\n", " tTdate = str(\n", " date(\n", " int(matches.group(\"year\")),\n", " int(matches.group(\"month\")),\n", " int(matches.group(\"day\")),\n", " )\n", " )\n", " tAccount = account\n", " tMemo = matches.group(\"memo\")\n", " tCountry = None\n", " tOutflow = \"0.00\"\n", " tInflow = matches.group(\"inflow\").strip().replace(\".\", \"\").replace(\",\", \".\").replace(\"-\", \"\")\n", " tOwner = input_dict[key][\"owner_id\"]\n", " tInstallmentNr = None\n", " tInstallmentTt = None\n", " tCreated = str(datetime.now(tz=None))\n", " tUpdated = None\n", " else:\n", " matches = re.match(pattern_to_use, item)\n", " tTdate = str(\n", " date(\n", " # partial files will not have the year data on transactions\n", " int(matches.group(\"year\")) if pattern_to_use == line_group_pattern else datetime.now().year,\n", " int(matches.group(\"month\")),\n", " int(matches.group(\"day\")),\n", " )\n", " )\n", " \n", " tAccount = account\n", "\n", " tMemo = matches.group(\"p_memo\") if matches.group(\"p_memo\") else matches.group(\"memo\")\n", " tInstallmentNr = int(matches.group(\"p_nr\")) if matches.group(\"p_nr\") else None\n", " tInstallmentTt = int(matches.group(\"p_tt\")) if matches.group(\"p_tt\") else None\n", "\n", " tCountry = matches.group(\"country\")\n", " tOutflow = matches.group(\"outflow\").strip().replace(\".\", \"\").replace(\",\", \".\")\n", " tInflow = matches.group(\"inflow\").strip().replace(\".\", \"\").replace(\",\", \".\")\n", " tOwner = input_dict[key][\"owner_id\"]\n", "\n", " tCreated = str(datetime.now(tz=None))\n", " tUpdated = None\n", "\n", " preHash = tTdate + tMemo + tOutflow + tInflow\n", " tId = hashlib.sha256(preHash.encode()).hexdigest()\n", "\n", " if matches.group(\"memo\") != \"Saldo Anterior\":\n", " insert_bulk.append(\n", " (\n", " tId,\n", " tTdate,\n", " tAccount,\n", " tMemo.strip(),\n", " tCountry,\n", " tOutflow,\n", " tInflow,\n", " tOwner,\n", " tInstallmentNr,\n", " tInstallmentTt,\n", " tCreated,\n", " tUpdated,\n", " )\n", " )\n", "\n", " return insert_bulk" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def db_insert(insert_bulk: list[tuple]):\n", " from mysql.connector import connect, Error\n", "\n", " try:\n", " with connect(\n", " host=\"127.0.0.1\",\n", " user=\"root\",\n", " password=\"pleasehashapasswordomg\",\n", " database=\"default\",\n", " ) as connection:\n", " print(\"CONNECTED!\", connection)\n", " with connection.cursor() as cursor:\n", " cursor.executemany(insert_query, insert_bulk)\n", " connection.commit()\n", " print(\"DONE!\")\n", " except Error as e:\n", " print(e)\n", " finally:\n", " connection.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def executor():\n", "\n", " import glob\n", "\n", " matched_files = glob.glob(\"./documents/OUROCARD*.txt\")\n", " # matched_files = glob.glob(\"./documents/OUROCARD_VISA_INFINITE-Mar_24.txt\")\n", "\n", " try:\n", " for file_name in matched_files:\n", " db_insert(build_insert(create_lists(file_name), 2))\n", " except:\n", " print(\"executor(): Error\")\n", " \n", " print(\"EXECUTOR COMPLETED.\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error during Transaction Lists creation\n", "executor(): Error\n", "EXECUTOR COMPLETED.\n" ] } ], "source": [ "executor()" ] } ], "metadata": { "kernelspec": { "display_name": "3.11.4", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 2 }