Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import folium | |
import streamlit as st | |
import pandas as pd | |
from streamlit_folium import st_folium | |
import time | |
st.set_page_config(layout="wide") | |
if "sleep_time" not in st.session_state: | |
st.session_state.sleep_time = 2 | |
if "auto_refresh" not in st.session_state: | |
st.session_state.auto_refresh = True | |
auto_refresh = st.sidebar.checkbox("Auto Refresh?", st.session_state.auto_refresh) | |
if auto_refresh: | |
number = st.sidebar.number_input("Refresh rate in seconds", value=st.session_state.sleep_time) | |
st.session_state.sleep_time = number | |
st.title("Nt3awnu نتعاونو") | |
# you can report more data here: https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708 | |
# description | |
st.markdown("Help us report more people in need by filling this form: https://forms.gle/nZNCUVog9ka2Vdqu6") | |
def parse_gg_sheet(url): | |
url = url.replace("edit#gid=", "export?format=csv&gid=") | |
df = pd.read_csv(url) | |
# parse latlng (column 4) to [lat, lng] | |
def parse_latlng(latlng): | |
if type(latlng) == str and "," in latlng: | |
lat, lng = latlng.split(",") | |
return [float(lat), float(lng)] | |
else: | |
return None | |
return df.assign(latlng=df.iloc[:, 4].apply(parse_latlng)) | |
df = parse_gg_sheet( | |
"https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708" | |
) | |
m = folium.Map(location=[31.628674, -7.992047], zoom_start=7.5) | |
for index, row in df.iterrows(): | |
if row["latlng"] is None: | |
continue | |
folium.Marker( | |
location=row["latlng"], | |
tooltip=row["العنوان أو اسم القرية"] if not pd.isna(row["العنوان أو اسم القرية"]) else None, | |
popup=row["رقم الهاتف (اختياري)"] if not pd.isna(row["رقم الهاتف (اختياري)"]) else None, | |
).add_to(m) | |
st_data = st_folium(m, use_container_width=True) | |
st.markdown( | |
""" | |
<iframe src="https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/" width="100%" height="600px"></iframe> | |
""", | |
unsafe_allow_html=True, | |
) | |
# st.markdown( | |
# """ | |
# <iframe src="https://docs.google.com/forms/d/e/1FAIpQLSfNrFHUScot5jQyRUJmor7kWYgwkkME6WqRgQG_L4Eze4RdHA/viewform?embedded=true" width="640" height="2877" frameborder="0" marginheight="0" marginwidth="0">Loading…</iframe> | |
# """, | |
# unsafe_allow_html=True, | |
# ) | |
if auto_refresh: | |
time.sleep(number) | |
st.experimental_rerun() | |