Weite me an app that allows me to track my spendings. Important data: who, what for, how much, date, category
Drop files here
or click to upload
import streamlit as st
from sqlalchemy import create_engine, Column, Integer, String, Float, Date
from sqlalchemy.orm import DeclarativeBase, Session
from datetime import datetime
class Base(DeclarativeBase):
pass
class Spending(Base):
__tablename__ = 'spendings'
id = Column(Integer, primary_key=True)
who = Column(String)
what_for = Column(String)
amount = Column(Float)
date = Column(Date)
category = Column(String)
# Create SQLite engine and create tables
engine = create_engine("sqlite:///spendings.sqlite")
Base.metadata.create_all(bind=engine)
st.title("Spending Tracker")
# Input fields for new spending entry
with st.form(key='spending_form'):
who = st.text_input("Who did the spending?")
what_for = st.text_input("What for?")
amount = st.number_input("Amount spent", min_value=0.0)
date = st.date_input("Date of spending", value=datetime.today())
category = st.text_input("Category of spending")
submit_button = st.form_submit_button(label='Add Spending')
if submit_button:
# Add new spending record to the database
with Session(engine) as session:
new_spending = Spending(who=who, what_for=what_for, amount=amount, date=date, category=category)
session.add(new_spending)
session.commit()
st.success("Spending added successfully!")
# Display spending records
st.header("All Spending Records")
with Session(engine) as session:
spendings = session.query(Spending).all()
spending_data = [{"Who": s.who, "What For": s.what_for, "Amount": s.amount, "Date": s.date, "Category": s.category} for s in spendings]
st.table(spending_data)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?