Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import os
|
|
| 5 |
|
| 6 |
# File to store diary entries
|
| 7 |
DATA_FILE = "diary_entries.json"
|
|
|
|
| 8 |
|
| 9 |
# Load existing diary entries
|
| 10 |
def load_entries():
|
|
@@ -16,33 +17,60 @@ def load_entries():
|
|
| 16 |
# Save diary entries
|
| 17 |
def save_entries(entries):
|
| 18 |
with open(DATA_FILE, "w") as file:
|
| 19 |
-
json.dump(entries, file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Main app function
|
| 22 |
def main():
|
| 23 |
-
st.
|
| 24 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# Load existing entries
|
| 27 |
diary_entries = load_entries()
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
st.success("Entry saved successfully!")
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
| 48 |
main()
|
|
|
|
| 5 |
|
| 6 |
# File to store diary entries
|
| 7 |
DATA_FILE = "diary_entries.json"
|
| 8 |
+
PASSWORD = "diary123" # Default password (can be customized)
|
| 9 |
|
| 10 |
# Load existing diary entries
|
| 11 |
def load_entries():
|
|
|
|
| 17 |
# Save diary entries
|
| 18 |
def save_entries(entries):
|
| 19 |
with open(DATA_FILE, "w") as file:
|
| 20 |
+
json.dump(entries, file, indent=4)
|
| 21 |
+
|
| 22 |
+
# Password verification
|
| 23 |
+
def verify_password():
|
| 24 |
+
if "password_verified" not in st.session_state:
|
| 25 |
+
st.session_state.password_verified = False
|
| 26 |
+
|
| 27 |
+
if not st.session_state.password_verified:
|
| 28 |
+
password_input = st.text_input("Enter Password:", type="password")
|
| 29 |
+
if st.button("Submit"):
|
| 30 |
+
if password_input == PASSWORD:
|
| 31 |
+
st.session_state.password_verified = True
|
| 32 |
+
st.success("Password verified!")
|
| 33 |
+
else:
|
| 34 |
+
st.error("Incorrect password. Try again.")
|
| 35 |
+
return False
|
| 36 |
+
return True
|
| 37 |
|
| 38 |
# Main app function
|
| 39 |
def main():
|
| 40 |
+
st.set_page_config(page_title="My Secret Diary", page_icon="📔", layout="centered")
|
| 41 |
+
st.title("📔 My Secret Diary")
|
| 42 |
+
st.markdown("Welcome to your personal diary! Keep your thoughts safe and organized.")
|
| 43 |
+
|
| 44 |
+
# Password verification
|
| 45 |
+
if not verify_password():
|
| 46 |
+
return
|
| 47 |
|
| 48 |
# Load existing entries
|
| 49 |
diary_entries = load_entries()
|
| 50 |
|
| 51 |
+
# Sidebar for navigation
|
| 52 |
+
st.sidebar.title("Navigation")
|
| 53 |
+
option = st.sidebar.radio("Choose an option:", ["Add Entry", "View Entries"])
|
| 54 |
|
| 55 |
+
if option == "Add Entry":
|
| 56 |
+
st.subheader("Add a New Diary Entry")
|
| 57 |
+
selected_date = st.date_input("Select a date", datetime.today())
|
| 58 |
+
entry_key = str(selected_date)
|
| 59 |
+
entry = st.text_area("Write your diary entry here:", value=diary_entries.get(entry_key, ""), height=200)
|
| 60 |
|
| 61 |
+
if st.button("Save Entry"):
|
| 62 |
+
diary_entries[entry_key] = entry
|
| 63 |
+
save_entries(diary_entries)
|
| 64 |
+
st.success("Entry saved successfully!")
|
|
|
|
| 65 |
|
| 66 |
+
elif option == "View Entries":
|
| 67 |
+
st.subheader("View Past Entries")
|
| 68 |
+
if not diary_entries:
|
| 69 |
+
st.info("No entries found. Start by adding a new entry!")
|
| 70 |
+
else:
|
| 71 |
+
selected_entry_key = st.selectbox("Select a date to view:", sorted(diary_entries.keys(), reverse=True))
|
| 72 |
+
st.write(f"**Entry for {selected_entry_key}:**")
|
| 73 |
+
st.write(diary_entries[selected_entry_key])
|
| 74 |
|
| 75 |
if __name__ == "__main__":
|
| 76 |
main()
|