|
|
|
@ -702,6 +702,123 @@ |
|
|
|
"\n", |
|
|
|
"\n", |
|
|
|
"print(files_only)" |
|
|
|
"print(files_only)" |
|
|
|
] |
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"cell_type": "code", |
|
|
|
|
|
|
|
"execution_count": 5, |
|
|
|
|
|
|
|
"metadata": {}, |
|
|
|
|
|
|
|
"outputs": [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"name": "stdout", |
|
|
|
|
|
|
|
"output_type": "stream", |
|
|
|
|
|
|
|
"text": [ |
|
|
|
|
|
|
|
"CONNECTED! <mysql.connector.connection_cext.CMySQLConnection object at 0x00000272B3BDD130>\n", |
|
|
|
|
|
|
|
"DONE!\n" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"source": [ |
|
|
|
|
|
|
|
"import csv\n", |
|
|
|
|
|
|
|
"from datetime import datetime\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Read the CSV file and extract the \"CATEGORY\" column\n", |
|
|
|
|
|
|
|
"categories = set()\n", |
|
|
|
|
|
|
|
"with open('PAYEE_FILTER.csv', newline='', encoding='utf-8') as csvfile:\n", |
|
|
|
|
|
|
|
" reader = csv.DictReader(csvfile)\n", |
|
|
|
|
|
|
|
" for row in reader:\n", |
|
|
|
|
|
|
|
" category = row['CATEGORY']\n", |
|
|
|
|
|
|
|
" if category: # Only add non-empty categories\n", |
|
|
|
|
|
|
|
" categories.add(category)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Create a list of tuples with the unique categories and current datetime as a string\n", |
|
|
|
|
|
|
|
"category_tuples = [(category, str(datetime.now(tz=None))) for category in categories]\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"insert_query = \"INSERT IGNORE INTO default.CATEGORY (NAME, CREATED) VALUES (%s, %s)\"\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"\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, category_tuples)\n", |
|
|
|
|
|
|
|
" connection.commit()\n", |
|
|
|
|
|
|
|
" print(\"DONE!\")\n", |
|
|
|
|
|
|
|
"except Error as e:\n", |
|
|
|
|
|
|
|
" print(e)\n", |
|
|
|
|
|
|
|
"finally:\n", |
|
|
|
|
|
|
|
" connection.close()" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"cell_type": "code", |
|
|
|
|
|
|
|
"execution_count": 3, |
|
|
|
|
|
|
|
"metadata": {}, |
|
|
|
|
|
|
|
"outputs": [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"name": "stdout", |
|
|
|
|
|
|
|
"output_type": "stream", |
|
|
|
|
|
|
|
"text": [ |
|
|
|
|
|
|
|
"[('Compras', '2024-11-08 12:28:12.251054'), ('Operacional', '2024-11-08 12:28:12.251054'), ('Renda', '2024-11-08 12:28:12.251054'), ('Transporte', '2024-11-08 12:28:12.251054'), ('Cora', '2024-11-08 12:28:12.251054'), ('Impostos', '2024-11-08 12:28:12.251054'), ('Alimentação', '2024-11-08 12:28:12.251054')]\n" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"source": [ |
|
|
|
|
|
|
|
"import csv\n", |
|
|
|
|
|
|
|
"from datetime import datetime\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Read the CSV file and extract the \"CATEGORY\" column\n", |
|
|
|
|
|
|
|
"categories = set()\n", |
|
|
|
|
|
|
|
"with open('PAYEE_FILTER.csv', newline='', encoding='utf-8') as csvfile:\n", |
|
|
|
|
|
|
|
" reader = csv.DictReader(csvfile)\n", |
|
|
|
|
|
|
|
" for row in reader:\n", |
|
|
|
|
|
|
|
" category = row['CATEGORY']\n", |
|
|
|
|
|
|
|
" if category: # Only add non-empty categories\n", |
|
|
|
|
|
|
|
" categories.add(category)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Create a list of tuples with the unique categories and current datetime as a string\n", |
|
|
|
|
|
|
|
"category_tuples = [(category, str(datetime.now(tz=None))) for category in categories]\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"print(category_tuples)" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"cell_type": "code", |
|
|
|
|
|
|
|
"execution_count": 3, |
|
|
|
|
|
|
|
"metadata": {}, |
|
|
|
|
|
|
|
"outputs": [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"name": "stdout", |
|
|
|
|
|
|
|
"output_type": "stream", |
|
|
|
|
|
|
|
"text": [ |
|
|
|
|
|
|
|
"[('Compras Digitais', '2024-11-08 15:27:36.418568'), ('Salários', '2024-11-08 15:27:36.418568'), ('Educação', '2024-11-08 15:27:36.418568'), ('Aplicativos', '2024-11-08 15:27:36.418568'), ('Restaurantes', '2024-11-08 15:27:36.418568'), ('Celular', '2024-11-08 15:27:36.418568'), ('PLR', '2024-11-08 15:27:36.418568'), ('Internet', '2024-11-08 15:27:36.418568'), ('Compras Físicas', '2024-11-08 15:27:36.418568'), ('Cashbacks', '2024-11-08 15:27:36.418568'), ('IOF', '2024-11-08 15:27:36.418568')]\n" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"source": [ |
|
|
|
|
|
|
|
"import csv\n", |
|
|
|
|
|
|
|
"from datetime import datetime\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Read the CSV file and extract the \"SUBCATEGORY\" column\n", |
|
|
|
|
|
|
|
"subcategories = set()\n", |
|
|
|
|
|
|
|
"with open('PAYEE_FILTER.csv', newline='', encoding='utf-8') as csvfile:\n", |
|
|
|
|
|
|
|
" reader = csv.DictReader(csvfile)\n", |
|
|
|
|
|
|
|
" for row in reader:\n", |
|
|
|
|
|
|
|
" subcategory = row['SUBCATEGORY']\n", |
|
|
|
|
|
|
|
" if subcategory: # Only add non-empty categories\n", |
|
|
|
|
|
|
|
" subcategories.add(subcategory)\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"# Create a list of tuples with the unique categories and current datetime as a string\n", |
|
|
|
|
|
|
|
"subcategory_tuples = [(subcategory, str(datetime.now(tz=None))) for subcategory in subcategories]\n", |
|
|
|
|
|
|
|
"\n", |
|
|
|
|
|
|
|
"print(subcategory_tuples)" |
|
|
|
|
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
], |
|
|
|
], |
|
|
|
"metadata": { |
|
|
|
"metadata": { |
|
|
|
@ -720,7 +837,7 @@ |
|
|
|
"name": "python", |
|
|
|
"name": "python", |
|
|
|
"nbconvert_exporter": "python", |
|
|
|
"nbconvert_exporter": "python", |
|
|
|
"pygments_lexer": "ipython3", |
|
|
|
"pygments_lexer": "ipython3", |
|
|
|
"version": "3.12.3" |
|
|
|
"version": "3.12.5" |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
"nbformat": 4, |
|
|
|
"nbformat": 4, |
|
|
|
|