add readme and add csv creation
This commit is contained in:
parent
af8aef236b
commit
63f02713e0
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
*.db
|
*.db
|
||||||
*.json
|
*.json
|
||||||
.idea/
|
.idea/
|
||||||
|
*.csv
|
||||||
@ -10,5 +10,4 @@ Steps
|
|||||||
* install required packages `pip install -r requirements.txt`
|
* install required packages `pip install -r requirements.txt`
|
||||||
* run `python3 main.py`
|
* run `python3 main.py`
|
||||||
* if successful will create a transactions.db (sqlite database)
|
* if successful will create a transactions.db (sqlite database)
|
||||||
* can be used with anyother tool to convert to csv
|
* also create csv
|
||||||
* one way to export to csv is is `https://www.sqlitetutorial.net/sqlite-export-csv/`
|
|
||||||
|
|||||||
21
main.py
21
main.py
@ -1,6 +1,9 @@
|
|||||||
# This is a sample Python script.
|
# This is a sample Python script.
|
||||||
import ijson
|
import ijson
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import pandas as pd
|
||||||
|
from glob import glob
|
||||||
|
from os.path import expanduser
|
||||||
|
|
||||||
# Press ⌃R to execute it or replace it with your code.
|
# Press ⌃R to execute it or replace it with your code.
|
||||||
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
|
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
|
||||||
@ -97,6 +100,20 @@ def write_to_database(tbl, cols):
|
|||||||
cur.execute(sql, values)
|
cur.execute(sql, values)
|
||||||
|
|
||||||
|
|
||||||
|
def make_csv_from_tables():
|
||||||
|
cur.execute("SELECT name FROM sqlite_master WHERE type='table'")
|
||||||
|
tbls = []
|
||||||
|
|
||||||
|
for (tbl,) in cur.fetchall():
|
||||||
|
print("tbl = ", tbl)
|
||||||
|
if tbl.find("transactions") == 0:
|
||||||
|
tbls.append(tbl)
|
||||||
|
|
||||||
|
for tbl in tbls:
|
||||||
|
clients = pd.read_sql(f"SELECT * FROM {tbl}", con)
|
||||||
|
clients.to_csv(f"{tbl}.csv", index=False)
|
||||||
|
|
||||||
|
|
||||||
def parse_json():
|
def parse_json():
|
||||||
extract_keys_names = extract_keys.keys()
|
extract_keys_names = extract_keys.keys()
|
||||||
headers = []
|
headers = []
|
||||||
@ -141,7 +158,9 @@ def parse_json():
|
|||||||
flat_json[k] = item[k]
|
flat_json[k] = item[k]
|
||||||
|
|
||||||
write_to_database(parent, flat_json)
|
write_to_database(parent, flat_json)
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
|
make_csv_from_tables()
|
||||||
|
|
||||||
|
|
||||||
# Press the green button in the gutter to run the script.
|
# Press the green button in the gutter to run the script.
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
ijson
|
ijson
|
||||||
|
pandas
|
||||||
Loading…
x
Reference in New Issue
Block a user