From 19e820b53c154bc8e5239b15103f9c91191ab643 Mon Sep 17 00:00:00 2001 From: rlbr Date: Sun, 16 Dec 2018 12:01:47 -0600 Subject: [PATCH] added files --- .gitignore | 115 ++++++++++++++++++++++++++++++++++++++++++++ db_wrapper_class.py | 49 +++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 .gitignore create mode 100644 db_wrapper_class.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..11614af --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/db_wrapper_class.py b/db_wrapper_class.py new file mode 100644 index 0000000..4189ec2 --- /dev/null +++ b/db_wrapper_class.py @@ -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;') \ No newline at end of file