commit
19e820b53c
2 changed files with 164 additions and 0 deletions
-
115.gitignore
-
49db_wrapper_class.py
@ -0,0 +1,115 @@ |
|||||
|
# Byte-compiled / optimized / DLL files |
||||
|
__pycache__/ |
||||
|
*.py[cod] |
||||
|
*$py.class |
||||
|
|
||||
|
# C extensions |
||||
|
*.so |
||||
|
|
||||
|
# Distribution / packaging |
||||
|
.Python |
||||
|
build/ |
||||
|
develop-eggs/ |
||||
|
dist/ |
||||
|
downloads/ |
||||
|
eggs/ |
||||
|
.eggs/ |
||||
|
lib/ |
||||
|
lib64/ |
||||
|
parts/ |
||||
|
sdist/ |
||||
|
var/ |
||||
|
wheels/ |
||||
|
share/python-wheels/ |
||||
|
*.egg-info/ |
||||
|
.installed.cfg |
||||
|
*.egg |
||||
|
MANIFEST |
||||
|
|
||||
|
# PyInstaller |
||||
|
# Usually these files are written by a python script from a template |
||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it. |
||||
|
*.manifest |
||||
|
*.spec |
||||
|
|
||||
|
# Installer logs |
||||
|
pip-log.txt |
||||
|
pip-delete-this-directory.txt |
||||
|
|
||||
|
# Unit test / coverage reports |
||||
|
htmlcov/ |
||||
|
.tox/ |
||||
|
.nox/ |
||||
|
.coverage |
||||
|
.coverage.* |
||||
|
.cache |
||||
|
nosetests.xml |
||||
|
coverage.xml |
||||
|
*.cover |
||||
|
.hypothesis/ |
||||
|
.pytest_cache/ |
||||
|
|
||||
|
# Translations |
||||
|
*.mo |
||||
|
*.pot |
||||
|
|
||||
|
# Django stuff: |
||||
|
*.log |
||||
|
local_settings.py |
||||
|
db.sqlite3 |
||||
|
|
||||
|
# Flask stuff: |
||||
|
instance/ |
||||
|
.webassets-cache |
||||
|
|
||||
|
# Scrapy stuff: |
||||
|
.scrapy |
||||
|
|
||||
|
# Sphinx documentation |
||||
|
docs/_build/ |
||||
|
|
||||
|
# PyBuilder |
||||
|
target/ |
||||
|
|
||||
|
# Jupyter Notebook |
||||
|
.ipynb_checkpoints |
||||
|
|
||||
|
# IPython |
||||
|
profile_default/ |
||||
|
ipython_config.py |
||||
|
|
||||
|
# pyenv |
||||
|
.python-version |
||||
|
|
||||
|
# celery beat schedule file |
||||
|
celerybeat-schedule |
||||
|
|
||||
|
# SageMath parsed files |
||||
|
*.sage.py |
||||
|
|
||||
|
# Environments |
||||
|
.env |
||||
|
.venv |
||||
|
env/ |
||||
|
venv/ |
||||
|
ENV/ |
||||
|
env.bak/ |
||||
|
venv.bak/ |
||||
|
|
||||
|
# Spyder project settings |
||||
|
.spyderproject |
||||
|
.spyproject |
||||
|
|
||||
|
# Rope project settings |
||||
|
.ropeproject |
||||
|
|
||||
|
# mkdocs documentation |
||||
|
/site |
||||
|
|
||||
|
# mypy |
||||
|
.mypy_cache/ |
||||
|
.dmypy.json |
||||
|
dmypy.json |
||||
|
|
||||
|
# Pyre type checker |
||||
|
.pyre/ |
||||
@ -0,0 +1,49 @@ |
|||||
|
from dateutil.parser import parse as date_parse |
||||
|
import csv |
||||
|
import re |
||||
|
import sqlite3 |
||||
|
noise = re.compile(r' {3,}.*') |
||||
|
def __init_db__(path): |
||||
|
con = sqlite3.connect(path) |
||||
|
cur = con.cursor() |
||||
|
cur.execute(''' |
||||
|
CREATE TABLE IF NOT EXISTS `transactions` ( |
||||
|
`details` STRING, |
||||
|
`date` STRING, |
||||
|
`amount` REAL, |
||||
|
`type` STRING, |
||||
|
`cOs_num` INTEGER, |
||||
|
UNIQUE( |
||||
|
`details`, |
||||
|
`date`, |
||||
|
`type`, |
||||
|
`amount`, |
||||
|
`cOs_num`));''') |
||||
|
con.commit() |
||||
|
return con |
||||
|
|
||||
|
class browser: |
||||
|
def __init__(self,db_path): |
||||
|
|
||||
|
self.db_path = db_path |
||||
|
self.con = __init_db__(db_path) |
||||
|
self.con.row_factory = sqlite3.Row |
||||
|
self.cur = self.con.cursor() |
||||
|
|
||||
|
def update_from_csv(self,csv_file): |
||||
|
with open(csv_file) as file: |
||||
|
reader = csv.DictReader(file) |
||||
|
l = list(reader) |
||||
|
for line in l: |
||||
|
date = line.pop('Posting Date') |
||||
|
cOs = line.pop('Check or Slip #') |
||||
|
line['date'] = date_parse(date) |
||||
|
line['Description'] = noise.sub('',line['Description']) |
||||
|
line['Amount'] = float(line['Amount']) |
||||
|
line['cOs'] = cOs |
||||
|
self.cur.executemany('INSERT OR IGNORE INTO `transactions` VALUES (:Description,:date,:Amount,:Type,:cOs);',l) |
||||
|
self.con.commit() |
||||
|
if __name__ == "__main__": |
||||
|
b = browser("test.db") |
||||
|
b.update_from_csv('test.csv') |
||||
|
res = b.cur.execute('SELECT * FROM transactions WHERE amount>=100;') |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue