Spaces:
Sleeping

Login / p.py
Pezh's picture
Rename app.py to p.py
c05fddd verified
Raw History Blame Contribute Delete
1.35 kB
import streamlit as st
import datetime
import base64
from datetime import datetime, timedelta
# Function to get the number of remaining clicks for the user
def get_remaining_clicks():
expiry_time = datetime.utcnow() + timedelta(hours=24) # Set the expiry time for 24 hours from now
user_id = st.report_thread.get_report_ctx().session_id # Get the user's session ID from the report context
click_count = st.session_state.get(user_id, {}).get('click_count', 10) # Get the current click count for the user
expiry_str = expiry_time.strftime('%Y-%m-%d %H:%M:%S') # Convert the expiry time to a string
return click_count, expiry_str
# Function to update the click count for the user
def update_click_count():
user_id = st.report_thread.get_report_ctx().session_id
click_count, expiry_str = get_remaining_clicks()
click_count -= 1
st.session_state[user_id] = {'click_count': click_count, 'expiry': expiry_str}
# Main app
def main():
st.title("Click Counter App")
click_count, expiry_str = get_remaining_clicks()
if click_count > 0:
if st.button("Click"):
update_click_count()
st.write(f"Clicked! You have {click_count-1} clicks remaining.")
else:
st.write("You have used up all your clicks for the next 24 hours.")
if __name__ == "__main__":
main()