Browse Source

updates

master
Yutsuo 2 years ago
parent
commit
1bf9a7a69d
  1. 4
      .vscode/settings.json
  2. 16
      clickhouse.sql
  3. 207
      nb_account_etl.ipynb
  4. 85
      nb_credit_card_etl.ipynb
  5. 119
      nb_lab.ipynb
  6. 2
      queries.sql
  7. 8
      robopato.code-workspace

4
.vscode/settings.json vendored

@ -0,0 +1,4 @@
{
"files.autoGuessEncoding": false,
"files.encoding": "iso88591"
}

16
clickhouse.sql

@ -0,0 +1,16 @@
CREATE TABLE TRANSACTION (
ID char(64) NOT NULL,
TDATE date NOT NULL,
ACCOUNT_ID integer NOT NULL,
MEMO varchar(64) NOT NULL,
COUNTRY char(2),
OUTFLOW decimal(20,2),
INFLOW decimal(12,2),
OWNER_ID integer,
INSTALLMENT_NR integer,
INSTALLMENT_TT integer,
CREATED datetime NOT NULL,
UPDATED datetime
)
ENGINE = MergeTree
PRIMARY KEY (ID)

207
nb_account_etl.ipynb

File diff suppressed because one or more lines are too long

85
nb_credit_card_etl.ipynb

File diff suppressed because one or more lines are too long

119
nb_lab.ipynb

@ -702,6 +702,123 @@
"\n",
"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": {
@ -720,7 +837,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.12.5"
}
},
"nbformat": 4,

2
queries.sql

@ -3,3 +3,5 @@ SELECT NOW();
TRUNCATE TABLE `default`.`TRANSACTION`;
UPDATE `TRANSACTION` SET MEMO = TRIM(MEMO)
ALTER TABLE `default`.SUBCATEGORY MODIFY COLUMN UPDATED datetime ON UPDATE CURRENT_TIMESTAMP NULL;

8
robopato.code-workspace

@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
Loading…
Cancel
Save