The enumerate() function have a parameter called "start" to tell the function where it should start the counting. So instead using idx + 1 we can use enumerate(categories, start = 1) and the idx will start from 1.
One easily-implemented but huge improvement would be to add a "payee" field that works the same as "category". I think I'd create separate tables for payee and category, too, but then it'd be more of a tutorial for sqlite than for python.
I did everything right and because I use Gentoo with systemd not rc the db packages for some reason don't work unless you have rc style init system, so all of your great toots about sql won't work for me, but I utilize db's on other servers where I run email servers and such, so I still get the benefit, thanks
C:\Users\memobe\PycharmProjects\demo4\venv\Scripts\python.exe C:\Users\memobe\PycharmProjects\demo4\venv\create_db.py Select any option below: 1. Input a new expense 2. View expenses summary 1 Enter the date of the expense (YYYY-MM-DD): 2023-01-17 Enter the description of the expense: food Traceback (most recent call last): File "C:\Users ey\PycharmProjects\demo4\venv\create_db.py", line 18, in cur.execute("SELECT DISTINCT category FROM expenses") sqlite3.OperationalError: no such table: expenses how come it wont work? heres what I copied: import sqlite3 conn = sqlite3.connect("expenses.db") cur = conn.cursor() while True: print("Select any option below:") print("1. Input a new expense") print("2. View expenses summary") choice = int(input()) if choice == 1: date = input("Enter the date of the expense (YYYY-MM-DD): ") description = input("Enter the description of the expense: ") cur.execute("SELECT DISTINCT category FROM expenses") categories = cur.fetchall() print("Select a category by number:") for idx, cetegory in enumerate(categories): print(f"{idx + 1}. {category[0]}") print(f"{len(categories) + 1}. Create a new category") category_choice = input() if category_choice == len(categories) + 1: category = input("Enter the new category name:") else: category = categories[category_choice -1][0] price = input("Enter the price of the expense: ") cur.execute("INSERT INTO expenses (Date, description, category, price) VALUES (?, ?, ?, ?,)", (date, description, category, price)) conn.commit() elif choice == 2: print("Select an option:") print("1. View all expenses") print("2. View monthly expenses by category") view_choice = int(input) if view_choice == 1: cur.execute("SELECT * FROM expenses") expenses = cur.fetchall() for expense in expenses: print(expense) pass elif view_choice == 2: month = input ("Enther the month (MM): ") year = input("Enter the year (YYYY): ") cur.execute("""SELECT category, SUM(price) FROM expenses WHERE strftime('%m', Data) = ? AND strftime('%Y', Date) = ? GROUP BY category""", (month, year)) expenses = cur.fetchall() for expense in expenses: print(f"Category: {expense[0]}, Total: {expense[1]}") else: exit() else: exit() repeat = input("Would you like to do something else more interesting (y/n)? ") if repeat.lower() !="y": break conn.close() please help anyone I really want to learn for my career
bro create_db.py should be a different file and this code should be in an different file named main.py create a file create_db.py and paste this import sqlite3 conn = sqlite3.connect("expenses.db") cur = conn.cursor() cur.execute("""CREATE TABLE IF NOT EXISTS expenses (id INTEGER PRIMARY KEY, Date DATE, description TEXT, category TEXT, price REAL)""") conn.commit() conn.close()
We can even use CSV file for saving expenses instead of database and can get visual presentation of our expenses category wise using matplotlib library
nice one, just remove 'Professional' from the title. This is not a professional expense manager by no means. I know you need to keep it short and it is a nice example how to build a tracker of some sort with a bit of python and SQL. It's a good start for sure, but not a professional one.
I tried the SELECT * FROM expenses in the expense.db that was created but it gave me this error(File "/Users/jerry/Desktop/Expense Tracker/expenses.db", line 1 SQLite format 3) what can i do, im not getting the results you are at the end.
The enumerate() function have a parameter called "start" to tell the function where it should start the counting. So instead using idx + 1 we can use enumerate(categories, start = 1) and the idx will start from 1.
One easily-implemented but huge improvement would be to add a "payee" field that works the same as "category".
I think I'd create separate tables for payee and category, too, but then it'd be more of a tutorial for sqlite than for python.
adding ui and graphs will be great .Thanks
Are we able to keep all of this data somewhere in a txt file or something?
Very nice. Thank you! I will adapt this for a project hours tracker.
That was so fun to do!
I did everything right and because I use Gentoo with systemd not rc the db packages for some reason don't work unless you have rc style init system, so all of your great toots about sql won't work for me, but I utilize db's on other servers where I run email servers and such, so I still get the benefit, thanks
Thanks For Sharing ❤
Great tutorial as usual. Thanks :)
How do you open your db file in pycharm? If I click on it literally nothing happens.
C:\Users\memobe\PycharmProjects\demo4\venv\Scripts\python.exe C:\Users\memobe\PycharmProjects\demo4\venv\create_db.py
Select any option below:
1. Input a new expense
2. View expenses summary
1
Enter the date of the expense (YYYY-MM-DD): 2023-01-17
Enter the description of the expense: food
Traceback (most recent call last):
File "C:\Users
ey\PycharmProjects\demo4\venv\create_db.py", line 18, in
cur.execute("SELECT DISTINCT category FROM expenses")
sqlite3.OperationalError: no such table: expenses
how come it wont work?
heres what I copied:
import sqlite3
conn = sqlite3.connect("expenses.db")
cur = conn.cursor()
while True:
print("Select any option below:")
print("1. Input a new expense")
print("2. View expenses summary")
choice = int(input())
if choice == 1:
date = input("Enter the date of the expense (YYYY-MM-DD): ")
description = input("Enter the description of the expense: ")
cur.execute("SELECT DISTINCT category FROM expenses")
categories = cur.fetchall()
print("Select a category by number:")
for idx, cetegory in enumerate(categories):
print(f"{idx + 1}. {category[0]}")
print(f"{len(categories) + 1}. Create a new category")
category_choice = input()
if category_choice == len(categories) + 1:
category = input("Enter the new category name:")
else:
category = categories[category_choice -1][0]
price = input("Enter the price of the expense: ")
cur.execute("INSERT INTO expenses (Date, description, category, price) VALUES (?, ?, ?, ?,)", (date, description, category, price))
conn.commit()
elif choice == 2:
print("Select an option:")
print("1. View all expenses")
print("2. View monthly expenses by category")
view_choice = int(input)
if view_choice == 1:
cur.execute("SELECT * FROM expenses")
expenses = cur.fetchall()
for expense in expenses:
print(expense)
pass
elif view_choice == 2:
month = input ("Enther the month (MM): ")
year = input("Enter the year (YYYY): ")
cur.execute("""SELECT category, SUM(price) FROM expenses
WHERE strftime('%m', Data) = ? AND strftime('%Y', Date) = ?
GROUP BY category""", (month, year))
expenses = cur.fetchall()
for expense in expenses:
print(f"Category: {expense[0]}, Total: {expense[1]}")
else:
exit()
else:
exit()
repeat = input("Would you like to do something else more interesting (y/n)?
")
if repeat.lower() !="y":
break
conn.close()
please help anyone I really want to learn for my career
bro create_db.py should be a different file and this code should be in an different file named main.py
create a file create_db.py and paste this
import sqlite3
conn = sqlite3.connect("expenses.db")
cur = conn.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS expenses
(id INTEGER PRIMARY KEY,
Date DATE,
description TEXT,
category TEXT,
price REAL)""")
conn.commit()
conn.close()
We can even use CSV file for saving expenses instead of database and can get visual presentation of our expenses category wise using matplotlib library
nice one, just remove 'Professional' from the title. This is not a professional expense manager by no means.
I know you need to keep it short and it is a nice example how to build a tracker of some sort with a bit of python and SQL. It's a good start for sure, but not a professional one.
super cool
This is the basic thing you can add tkinter and modern gui to it or html pyscript thing
SQL integration into Pycharm seems to be a paid option, isn't any free option out there for educational purpose?
if u are a student you can get pycharm professional for free
Thank you bro..
I dont know why, but it will not allow me to do these codes, can someone help?
How to build GUI for this?
hello,
try to talk about reinforcement learning for chabot bro
Please make 🙏🙏🙏🙏 a video on Python Wireless Thermal Printer using Bluetooth from Android mobile
Lol this guy can't code
I tried the SELECT * FROM expenses in the expense.db that was created but it gave me this error(File "/Users/jerry/Desktop/Expense Tracker/expenses.db", line 1
SQLite format 3) what can i do, im not getting the results you are at the end.
Im using VScode not pycham
Please make 🙏🙏🙏🙏 a video on Python Wireless Thermal Printer using Bluetooth from Android mobile
Please make 🙏🙏🙏🙏 a video on Python Wireless Thermal Printer using Bluetooth from Android mobile