Upload app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,30 @@ def load_css() -> None:
|
|
| 23 |
st.markdown(f"<style>{css_file.read()}</style>", unsafe_allow_html=True)
|
| 24 |
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def initialize_state() -> None:
|
| 27 |
if "cards" not in st.session_state:
|
| 28 |
st.session_state.cards = []
|
|
@@ -134,8 +158,9 @@ browser_time_value = streamlit_js_eval(
|
|
| 134 |
want_output=True,
|
| 135 |
key="browser_time_eval",
|
| 136 |
)
|
| 137 |
-
|
| 138 |
-
|
|
|
|
| 139 |
fetch_cards_once()
|
| 140 |
render_top_buttons(add_card, check_time)
|
| 141 |
render_header()
|
|
|
|
| 23 |
st.markdown(f"<style>{css_file.read()}</style>", unsafe_allow_html=True)
|
| 24 |
|
| 25 |
|
| 26 |
+
def parse_browser_time(value) -> dict[str, str] | None:
|
| 27 |
+
if not value:
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
if isinstance(value, dict):
|
| 31 |
+
if {"date", "hour", "minute"} <= set(value.keys()):
|
| 32 |
+
return {
|
| 33 |
+
"date": str(value["date"]),
|
| 34 |
+
"hour": str(value["hour"]).zfill(2),
|
| 35 |
+
"minute": str(value["minute"]).zfill(2),
|
| 36 |
+
}
|
| 37 |
+
return None
|
| 38 |
+
|
| 39 |
+
if isinstance(value, str):
|
| 40 |
+
text = value.strip()
|
| 41 |
+
try:
|
| 42 |
+
parsed = json.loads(text)
|
| 43 |
+
except json.JSONDecodeError:
|
| 44 |
+
return None
|
| 45 |
+
return parse_browser_time(parsed)
|
| 46 |
+
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
def initialize_state() -> None:
|
| 51 |
if "cards" not in st.session_state:
|
| 52 |
st.session_state.cards = []
|
|
|
|
| 158 |
want_output=True,
|
| 159 |
key="browser_time_eval",
|
| 160 |
)
|
| 161 |
+
parsed_browser_time = parse_browser_time(browser_time_value)
|
| 162 |
+
if parsed_browser_time:
|
| 163 |
+
st.session_state.browser_time = parsed_browser_time
|
| 164 |
fetch_cards_once()
|
| 165 |
render_top_buttons(add_card, check_time)
|
| 166 |
render_header()
|