chandralegend's picture
added persistant level and logo
5c03cbf
raw
history blame
1.36 kB
import streamlit as st
from utils.login import get_login
import os
def initialize_level():
if 'level' not in st.session_state:
if get_login()["status"]:
if not os.path.exists(f".sessions/{get_login()['username']}/level.txt"):
with open(f".sessions/{get_login()['username']}/level.txt", "w") as f:
f.write("0")
st.session_state['level'] = 0
else:
with open(f".sessions/{get_login()['username']}/level.txt", "r") as f:
st.session_state['level'] = int(f.read())
def get_level():
return st.session_state['level']
def render_page(page, level):
if get_login()["status"]:
if st.session_state['level'] < level:
st.error(f"You need to complete Level {st.session_state['level']} first!")
else:
page()
else:
st.error("You need to login first!")
def complete_level(level):
if st.session_state['level'] > level:
st.info(f'You have Already completed Level {level}!')
else:
st.session_state['level'] = level + 1
with open(f".sessions/{get_login()['username']}/level.txt", "w") as f:
f.write(str(st.session_state['level']))
st.balloons()
st.success(f'You have completed Level {level}! You can now move on to the next level.')