diff --git a/.vscode/launch.json b/.vscode/launch.json index 9c519d0..1c8615d 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,15 @@ "program": "main.py", "console": "integratedTerminal", "justMyCode": true, - "args": ["C:\\Users\\saram\\Downloads\\Statement_082022_4653.pdf"] + "args": ["C:\\Users\\saram\\Downloads\\Statement_072022_4653.pdf"] + }, + { + "name": "Create Database", + "type": "python", + "request": "launch", + "program": "database.py", + "console": "integratedTerminal", + "justMyCode": true } ] } \ No newline at end of file diff --git a/database.py b/database.py index 8496df9..d2f0f6f 100755 --- a/database.py +++ b/database.py @@ -9,30 +9,33 @@ def create_tables(): with instance: instance.create_tables([User, TransactionCategory, Transaction, Source]) +def add_user(): # Make my user. instance.connect() User.create(username='ciphercules') instance.close() def add_default_categories(): + """Helper function to add default categories. Should be called manually.""" categories = [ - {"food": ["snacks", "fast_food", "groceries", "restaurant"]}, - {"clothing": []}, - {"event": ["event_food", "birthday", "movie_theater"]}, - {"finance": ["interest"]}, - {"hobby": ["gym", "game_development", "projects", "education"]}, - {"home_improvement": []}, - {"pet": ["health", "dog_food"]}, - {"media": ["book", "music", "television", "video_game"]}, - {"health": ["medicine"]}, - {"transit": ["car_insurance", "car_registration", "gas", "parking", "taxi", "car_maintenance"]}, - {"utilities": ["electricity", "gas", "laundry", "cell_phone", "trash", "water"]}, - {"rent": []}, + ("food", ["snacks", "fast_food", "groceries", "restaurant"]), + ("clothing", []), + ("event", ["event_food", "birthday", "movie_theater"]), + ("finance", ["interest"]), + ("hobby", ["gym", "game_development", "projects", "education"]), + ("home_improvement", []), + ("pet", ["dog_health", "dog_food"]), + ("media", ["book", "music", "television", "video_game"]), + ("health", ["medicine"]), + ("transit", ["car_insurance", "car_registration", "gas", "parking", "taxi", "car_maintenance"]), + ("utilities", ["electricity", "natural_gas", "laundry", "cell_phone", "trash", "water"]), + ("rent", []), ] instance.connect() with instance.atomic(): - for parent, children in categories.items(): + for category in categories: + parent, children = category parent_db = TransactionCategory.create(name=parent) for child in children: TransactionCategory.create(name=child, parent=parent_db) @@ -66,4 +69,9 @@ class Transaction(BaseModel): transaction_date = DateTimeField() description = CharField() amount = FloatField() - subcategory = ForeignKeyField(TransactionCategory, backref='+', null=True) \ No newline at end of file + subcategory = ForeignKeyField(TransactionCategory, backref='+', null=True) + +if __name__ == "__main__": + create_tables() + add_user() + add_default_categories() \ No newline at end of file diff --git a/todo.txt b/todo.txt index 940509e..d7b96d2 100755 --- a/todo.txt +++ b/todo.txt @@ -7,8 +7,8 @@ Every week, I need to: ## Parse capital one statement x Given a PDF bank statement from capital one, extract the transaction date, description, and amount from each transaction -Store the data in a SQL lite database +xStore the data in a SQL lite database x Create database schema x Automatically add capital one transactions to database -Add web page to add categories -Add web page to categorize transactions \ No newline at end of file +Add web page to categorize transactions +Add web page to add categories \ No newline at end of file