diff --git a/.vscode/launch.json b/.vscode/launch.json index a4ddf99..5be0237 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,12 @@ "program": "main.py", "console": "integratedTerminal", "justMyCode": true, - "args": ["C:\\Users\\saram\\Downloads\\Statement_072022_4653.pdf"] + "args": [ + // "C:\\Users\\saram\\Downloads\\Statement_072022_4653.pdf", + // "C:\\Users\\saram\\Downloads\\Statement_082022_4653.pdf", + "C:\\Users\\saram\\Downloads\\Statement_092022_4653.pdf", + "C:\\Users\\saram\\Downloads\\Statement_102022_4653.pdf", + ] }, { "name": "Create Database", diff --git a/app.py b/app.py index e436922..da6dd6c 100755 --- a/app.py +++ b/app.py @@ -105,23 +105,40 @@ def transaction(uuid=None): # Default if no method is hit abort(400) -@app.route("/categories") +@app.route("/categories", methods=["GET", "POST"]) def categories(): - try: - raw_categories = database.TransactionCategory.select() - categories = {} - for category in raw_categories: - if not category.parent: - categories[category.name] = [] + if request.method == "GET": + try: + raw_categories = database.TransactionCategory.select() + categories = {} + for category in raw_categories: + if not category.parent: + categories[category.name] = [] - for category in raw_categories: - if category.parent: - categories[category.parent.name].append(category.name) + for category in raw_categories: + if category.parent: + categories[category.parent.name].append(category.name) - return categories - except peewee.DoesNotExist: - abort(404) - except: - abort(500) + return categories + except peewee.DoesNotExist: + abort(404) + except: + abort(500) + if request.method == "POST": + body = request.get_json() + try: + if 'parent' in body: + parent = database.TransactionCategory.get(database.TransactionCategory.name == body['parent']) + database.TransactionCategory.create(name=body['name'], parent=parent) + else: + database.TransactionCategory.create(name=body['name']) + return ('', 200) + except peewee.DoesNotExist: + abort(404) + except: + abort(500) + + # Should never get here. + abort(500) app.run() \ No newline at end of file diff --git a/budget.db b/budget.db new file mode 100755 index 0000000..58e8bc5 Binary files /dev/null and b/budget.db differ diff --git a/capital_one.py b/capital_one.py index 513b28d..e7a1fe5 100755 --- a/capital_one.py +++ b/capital_one.py @@ -53,12 +53,15 @@ class Transactions(Regex): date = result[0] description = " ".join(result[1].split()) - is_payment = '-' in result[2] + is_credit = '-' in result[2] amount = float(result[3].replace(',', '')) - if is_payment: - print(f"Skipping payment: {amount}") - continue + if is_credit: + if "AUTOPAY" in description: + print(f"Skipping payment: {amount}") + continue + + amount *= -1 transactions.append([date, description, amount]) diff --git a/database.py b/database.py index 2d45cf4..5be8a4c 100755 --- a/database.py +++ b/database.py @@ -41,6 +41,15 @@ def add_default_categories(): for child in children: TransactionCategory.create(name=child, parent=parent_db) + +def delete_transactions(): + instance.connect() + # august_2022 = datetime.datetime(2022, 8, 18, 0) + # delete_query = Transaction.delete().where(Transaction.transaction_date > august_2022) + delete_query = Transaction.delete().where(Transaction.primary_key == 83) + delete_query.execute() + instance.close() + class BaseModel(Model): class Meta: database = instance diff --git a/main.py b/main.py index 9a0d7de..a45086f 100755 --- a/main.py +++ b/main.py @@ -34,7 +34,7 @@ for f in args.files: transaction_date=date, description=description, amount=amount, - source_filename=filename, + source_file=filename, type=file_parser.source ) database.instance.close() diff --git a/templates/index.html b/templates/index.html index 2b805b4..fb93f26 100755 --- a/templates/index.html +++ b/templates/index.html @@ -100,6 +100,12 @@ +

Add category

+ + + + +