Fix default categories

This commit is contained in:
Sara Montecino 2022-10-30 02:58:27 -07:00
parent ac6763df1b
commit 001d589a1e
3 changed files with 34 additions and 18 deletions

10
.vscode/launch.json vendored
View File

@ -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
}
]
}

View File

@ -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)
subcategory = ForeignKeyField(TransactionCategory, backref='+', null=True)
if __name__ == "__main__":
create_tables()
add_user()
add_default_categories()

View File

@ -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
Add web page to categorize transactions
Add web page to add categories