Files
bitcoin/app.py
T

116 lines
5.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import streamlit as st
import pandas as pd
from pathlib import Path
from datetime import date, time
DATA_DIR = Path("data")
TODO_FILE = DATA_DIR / "todo.csv"
CALENDAR_FILE = DATA_DIR / "calendar.csv"
DATA_DIR.mkdir(parents=True, exist_ok=True)
TODO_COLUMNS = [
"id","titel","beschreibung","kategorie","prioritaet","status",
"faellig_am","wiederholen","notiz"
]
CALENDAR_COLUMNS = [
"id","titel","datum","uhrzeit","dauer_min","kalender","kategorie",
"erinnerung_min","wiederholen","notiz"
]
def load_csv(path: Path, columns: list[str]) -> pd.DataFrame:
if path.exists():
df = pd.read_csv(path)
for col in columns:
if col not in df.columns:
df[col] = ""
return df[columns]
return pd.DataFrame(columns=columns)
def save_csv(df: pd.DataFrame, path: Path) -> None:
df.to_csv(path, index=False)
def next_id(df: pd.DataFrame) -> int:
if df.empty or "id" not in df.columns:
return 1
try:
return int(df["id"].max()) + 1
except Exception:
return 1
st.set_page_config(page_title="Bitcoin-Programm", layout="wide")
st.title("Bitcoin-Programm – To-do & Kalender")
tab1, tab2, tab3 = st.tabs(["To-do anlegen", "Kalendertermin anlegen", "Daten ansehen"])
with tab1:
st.subheader("Neues To-do")
todo_df = load_csv(TODO_FILE, TODO_COLUMNS)
new_todo_id = next_id(todo_df)
with st.form("todo_form", clear_on_submit=True):
titel = st.text_input("Titel")
beschreibung = st.text_area("Beschreibung")
kategorie = st.selectbox("Kategorie", ["Allgemein", "Bitcoin", "Dokumentation", "Kalender", "Admin", "Sonstiges"])
prioritaet = st.selectbox("Priorität", ["Niedrig", "Mittel", "Hoch"])
status = st.selectbox("Status", ["Offen", "In Arbeit", "Wartet", "Erledigt"])
faellig_am = st.date_input("Fällig am", value=date.today())
wiederholen = st.selectbox("Wiederholen", ["Nein", "Täglich", "Wöchentlich", "Monatlich"])
notiz = st.text_area("Notiz")
submitted = st.form_submit_button("To-do speichern")
if submitted:
if not titel.strip():
st.error("Bitte mindestens einen Titel eingeben.")
else:
new_row = pd.DataFrame([{
"id": new_todo_id,
"titel": titel,
"beschreibung": beschreibung,
"kategorie": kategorie,
"prioritaet": prioritaet,
"status": status,
"faellig_am": faellig_am.isoformat(),
"wiederholen": wiederholen,
"notiz": notiz,
}])
todo_df = pd.concat([todo_df, new_row], ignore_index=True)
save_csv(todo_df, TODO_FILE)
st.success("To-do gespeichert.")
with tab2:
st.subheader("Neuen Kalendereintrag")
cal_df = load_csv(CALENDAR_FILE, CALENDAR_COLUMNS)
new_cal_id = next_id(cal_df)
with st.form("calendar_form", clear_on_submit=True):
titel = st.text_input("Titel")
datum = st.date_input("Datum", value=date.today())
uhrzeit = st.time_input("Uhrzeit", value=time(9, 0))
dauer_min = st.number_input("Dauer in Minuten", min_value=5, max_value=1440, value=60, step=5)
kalender = st.selectbox("Kalender", ["Arbeit", "Privat", "Bitcoin", "Todo"])
kategorie = st.selectbox("Kategorie", ["Meeting", "Aufgabe", "Erinnerung", "Termin", "Sonstiges"])
erinnerung_min = st.number_input("Erinnerung vorab in Minuten", min_value=0, max_value=10080, value=30, step=5)
wiederholen = st.selectbox("Wiederholen", ["Nein", "Täglich", "Wöchentlich", "Monatlich"])
notiz = st.text_area("Notiz")
submitted = st.form_submit_button("Kalendertermin speichern")
if submitted:
if not titel.strip():
st.error("Bitte mindestens einen Titel eingeben.")
else:
new_row = pd.DataFrame([{
"id": new_cal_id,
"titel": titel,
"datum": datum.isoformat(),
"uhrzeit": uhrzeit.strftime("%H:%M"),
"dauer_min": int(dauer_min),
"kalender": kalender,
"kategorie": kategorie,
"erinnerung_min": int(erinnerung_min),
"wiederholen": wiederholen,
"notiz": notiz,
}])
cal_df = pd.concat([cal_df, new_row], ignore_index=True)
save_csv(cal_df, CALENDAR_FILE)
st.success("Kalendertermin gespeichert.")
with tab3:
st.subheader("Gespeicherte Daten")
col1, col2 = st.columns(2)
with col1:
st.markdown("### To-dos")
todo_df = load_csv(TODO_FILE, TODO_COLUMNS)
st.dataframe(todo_df, use_container_width=True)
st.download_button("To-do CSV herunterladen", data=todo_df.to_csv(index=False).encode("utf-8"), file_name="todo.csv", mime="text/csv")
with col2:
st.markdown("### Kalender")
cal_df = load_csv(CALENDAR_FILE, CALENDAR_COLUMNS)
st.dataframe(cal_df, use_container_width=True)
st.download_button("Kalender CSV herunterladen", data=cal_df.to_csv(index=False).encode("utf-8"), file_name="calendar.csv", mime="text/csv")