commit 2cf0274a414f5c14014c7f56719490fe27af854b Author: Dejan Rožič Date: Tue Jan 6 13:31:58 2026 +0100 first commit diff --git a/main.py b/main.py new file mode 100644 index 0000000..57317e2 --- /dev/null +++ b/main.py @@ -0,0 +1,64 @@ +import time +import requests +import streamlit as st + +CAM_URLS = [ + ("Celje SD (DARS)", "https://kamere.dars.si/kamere/Baza_Konjice/Celje_SD.jpg"), + ("Sp. Stražišče (DRSC)", "https://www.drsc.si/kamere/kamslike/SpodnjeStranice/Sst1_0001.jpg"), + ("Rogaška (DRSC)", "https://www.drsc.si/kamere/KamSlike/Rogaska/Slike/Rog1_0001.jpg"), +] + +st.set_page_config(page_title="Road Cameras", layout="wide") +st.title("Road Cameras") + +refresh_s = st.sidebar.number_input( + "Refresh interval (seconds)", + min_value=0.5, + max_value=60.0, + value=10.0, + step=0.5 +) +cols_n = st.sidebar.slider("Columns", 1, 4, 2) +auto = st.sidebar.toggle("Auto refresh", value=True) + +def fetch_image_bytes(url: str) -> bytes: + cb_url = f"{url}?_ts={int(time.time() * 1000)}" + headers = { + "User-Agent": "Mozilla/5.0", + "Accept": "image/jpeg,image/*,*/*;q=0.8", + "Cache-Control": "no-cache", + "Pragma": "no-cache", + } + r = requests.get(cb_url, timeout=8, headers=headers) + r.raise_for_status() + return r.content + +# Keep last good image in session_state, so 503 doesn't blank the UI +if "last_images" not in st.session_state: + st.session_state.last_images = {} # name -> bytes + +def render_all(): + cols = st.columns(cols_n) + for i, (name, url) in enumerate(CAM_URLS): + with cols[i % cols_n]: + st.subheader(name) + try: + img = fetch_image_bytes(url) + st.session_state.last_images[name] = img + st.image(img, use_container_width=True) + st.caption("✅ OK") + except Exception as e: + # show last good frame if available + last = st.session_state.last_images.get(name) + if last: + st.image(last, use_container_width=True) + st.caption(f"⚠️ Using last good frame ({e})") + else: + st.warning(f"No image yet ({e})") + +render_all() +st.caption(f"Last update: {time.strftime('%Y-%m-%d %H:%M:%S')}") + +if auto: + time.sleep(float(refresh_s)) + st.rerun() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f1c47e6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +streamlit +requests \ No newline at end of file