Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import json
|
|
|
4 |
|
5 |
def save_user_data(email, data):
|
6 |
"""Save user data to a file named after the user's email."""
|
@@ -18,6 +19,13 @@ def list_saved_users():
|
|
18 |
"""List all files (users) with saved states containing '@' in filename."""
|
19 |
return [f[:-4] for f in os.listdir() if f.endswith('.txt') and '@' in f]
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
def display_social_links(social_data):
|
22 |
"""Display social media links as Markdown."""
|
23 |
st.markdown("## Social Media Links")
|
@@ -54,13 +62,19 @@ def main():
|
|
54 |
|
55 |
# Save data when changes are made
|
56 |
if st.button("Save Data"):
|
57 |
-
save_user_data(new_email, cached_data)
|
58 |
st.sidebar.success("Data updated and saved!")
|
59 |
|
60 |
-
#
|
61 |
-
if
|
62 |
-
st.
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
# Display current data without password
|
66 |
display_data = cached_data.copy()
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
import json
|
4 |
+
import base64
|
5 |
|
6 |
def save_user_data(email, data):
|
7 |
"""Save user data to a file named after the user's email."""
|
|
|
19 |
"""List all files (users) with saved states containing '@' in filename."""
|
20 |
return [f[:-4] for f in os.listdir() if f.endswith('.txt') and '@' in f]
|
21 |
|
22 |
+
def get_file_download_link(filename):
|
23 |
+
"""Generate a file download link."""
|
24 |
+
with open(filename, "rb") as file:
|
25 |
+
base64_file = base64.b64encode(file.read()).decode()
|
26 |
+
href = f'<a href="data:file/txt;base64,{base64_file}" download="{filename}">Download {filename}</a>'
|
27 |
+
return href
|
28 |
+
|
29 |
def display_social_links(social_data):
|
30 |
"""Display social media links as Markdown."""
|
31 |
st.markdown("## Social Media Links")
|
|
|
62 |
|
63 |
# Save data when changes are made
|
64 |
if st.button("Save Data"):
|
65 |
+
save_user_data(new_email, {'email': new_email, 'phone': new_phone, 'password': new_password, 'social': cached_data['social']})
|
66 |
st.sidebar.success("Data updated and saved!")
|
67 |
|
68 |
+
# Download link for user data file
|
69 |
+
if selected_user and selected_user != 'New User':
|
70 |
+
st.sidebar.markdown(get_file_download_link(f"{selected_user}.txt"), unsafe_allow_html=True)
|
71 |
+
|
72 |
+
# File uploader
|
73 |
+
uploaded_file = st.sidebar.file_uploader("📤 Upload User File", type='txt')
|
74 |
+
if uploaded_file is not None:
|
75 |
+
uploaded_data = json.loads(uploaded_file.getvalue().decode())
|
76 |
+
save_user_data(uploaded_data['email'], uploaded_data)
|
77 |
+
st.sidebar.success("Uploaded and saved!")
|
78 |
|
79 |
# Display current data without password
|
80 |
display_data = cached_data.copy()
|