temii001's picture
Update app.py
cc49087 verified
import streamlit as st
from datetime import date
import os
# πŸ”§ Custom path for the TXT file
TXT_FILE = r"C:\Users\Temoor Iqbal\Documents\mood_tracker.txt"
# Streamlit UI
st.title("🧠 Daily Mood Tracker (TXT Version)")
st.write("Track your daily mood and store it in a simple text file.")
# Today's date
today = date.today().strftime("%Y-%m-%d")
# Mood input
mood = st.selectbox("How are you feeling today?", [
"πŸ™‚ Happy", "😐 Okay", "πŸ˜” Sad", "😑 Angry", "😩 Stressed", "😴 Tired", "🀩 Excited"
])
# Save mood
if st.button("Save Mood"):
if os.path.exists(TXT_FILE):
with open(TXT_FILE, "r") as file:
content = file.read()
else:
content = ""
if today in content:
st.warning("Mood for today is already recorded.")
else:
with open(TXT_FILE, "a") as file:
file.write(f"{today} - {mood}\n")
st.success("Mood saved successfully!")
# 🚫 Delete today's mood
if st.button("Delete Today's Mood"):
if os.path.exists(TXT_FILE):
with open(TXT_FILE, "r") as file:
lines = file.readlines()
# Remove today's line
new_lines = [line for line in lines if not line.startswith(today)]
if len(lines) == len(new_lines):
st.warning("No mood recorded for today to delete.")
else:
with open(TXT_FILE, "w") as file:
file.writelines(new_lines)
st.success("Today's mood deleted successfully.")
else:
st.warning("Mood file not found.")
# Show mood history
st.subheader("πŸ“Š Mood History")
if os.path.exists(TXT_FILE):
with open(TXT_FILE, "r") as file:
history = file.read()
st.text(history)
else:
st.info("No mood history found yet.")