forked from scanion/Teller
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathteller.py
42 lines (28 loc) · 1.06 KB
/
teller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import argparse
import sqlite3
from teller import pdf_processor
from teller import db_manager
def main():
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('database')
arg_parser.add_argument('-d', dest='directory', required=False)
args = arg_parser.parse_args()
directory = 'statements'
if args.directory:
assert os.path.exists(args.directory)
directory = args.directory
with sqlite3.connect(args.database) as db_conn:
try:
db_manager.create_db(db_conn)
except sqlite3.OperationalError: # db exists
pass
print(f"Searching for pdfs in '{directory}'...")
found_trans = pdf_processor.get_transactions(directory)
print(f"Found {len(found_trans)} transactions in pdf statements")
existing_trans = db_manager.get_existing_trans(db_conn)
to_add = found_trans - existing_trans
print(f"Adding {len(to_add)} new transactions to db...")
db_manager.add_to_db(db_conn, to_add)
if __name__ == '__main__':
main()