File size: 1,025 Bytes
6862f85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

import streamlit as st
from streamlit_cookies_manager import EncryptedCookieManager
import os
import warnings

cookies = EncryptedCookieManager(
    # This prefix will get added to all your cookie names.
    # This way you can run your app on Streamlit Cloud without cookie name clashes with other apps.
    prefix="LUL/streamlit-cookies-manager/",
    # You should really setup a long COOKIES_PASSWORD secret if you're running on Streamlit Cloud.
    password=os.environ.get("COOKIES_PASSWORD", "uDnda87,kGFdi&jh.kjsk/jk4DF369*^jhGks"),
)
warnings.filterwarnings("ignore")
import uuid
from datetime import datetime, timedelta

@st.cache_data
def gener():
   user_id = str(uuid.uuid4()) # generate a random user id
   expiration_date = datetime.now() + timedelta(days=365) # set expiration date to one year from now
   cookies['user_id'] = user_id# set the cookie

user_id = cookies['user_id'] # get the cookie value
if user_id is not None:
    st.write(f"Your user id is {user_id}") # display the user id
else:
    gener()