Spaces:
Sleeping
Sleeping
- Qr code
Browse files- Histats visit counter
- fix admin exit
app.py
CHANGED
@@ -8,10 +8,12 @@ if "UUID" not in st.session_state:
|
|
8 |
|
9 |
poll_name = st.query_params.get("poll")
|
10 |
if poll_name:
|
11 |
-
|
12 |
st.session_state["selected_poll_name"] = poll_name
|
13 |
|
14 |
if "selected_poll_name" not in st.session_state:
|
15 |
home.load()
|
16 |
else :
|
17 |
-
poll.load()
|
|
|
|
|
|
8 |
|
9 |
poll_name = st.query_params.get("poll")
|
10 |
if poll_name:
|
11 |
+
|
12 |
st.session_state["selected_poll_name"] = poll_name
|
13 |
|
14 |
if "selected_poll_name" not in st.session_state:
|
15 |
home.load()
|
16 |
else :
|
17 |
+
poll.load()
|
18 |
+
|
19 |
+
utils.statistics()
|
poll.py
CHANGED
@@ -7,6 +7,8 @@ def exit_poll():
|
|
7 |
set_votes([])
|
8 |
st.query_params.pop("poll")
|
9 |
del st.session_state["selected_poll_name"]
|
|
|
|
|
10 |
|
11 |
def set_votes(votes=[]):
|
12 |
poll = utils.find_poll(st.session_state["selected_poll_name"])
|
@@ -36,6 +38,7 @@ def clear_votes_section():
|
|
36 |
|
37 |
def delete_poll():
|
38 |
utils.load_polls().remove(utils.find_poll(st.session_state["selected_poll_name"]))
|
|
|
39 |
del st.session_state["selected_poll_name"]
|
40 |
|
41 |
|
@@ -67,18 +70,28 @@ def load_votes():
|
|
67 |
st.button("Clear Votes", on_click=clear_votes_section, use_container_width=True)
|
68 |
st.button("Delete Poll", on_click=delete_poll, use_container_width=True)
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
def load():
|
71 |
selected_poll_name = st.session_state["selected_poll_name"]
|
72 |
-
st.write("
|
73 |
columns = st.columns(3)
|
74 |
with columns[0]:
|
75 |
-
st.button("Exit", on_click=exit_poll)
|
76 |
with columns[1]:
|
77 |
-
st.button("Refresh")
|
78 |
with columns[2]:
|
79 |
-
st.link_button("Link To Poll", "?poll="+selected_poll_name, type="primary")
|
|
|
80 |
st.title(selected_poll_name)
|
81 |
if not is_admin():
|
82 |
load_voting()
|
83 |
else:
|
84 |
-
load_votes()
|
|
|
|
|
|
|
|
7 |
set_votes([])
|
8 |
st.query_params.pop("poll")
|
9 |
del st.session_state["selected_poll_name"]
|
10 |
+
if "selected_poll_admin_password" in st.session_state:
|
11 |
+
del st.session_state["selected_poll_admin_password"]
|
12 |
|
13 |
def set_votes(votes=[]):
|
14 |
poll = utils.find_poll(st.session_state["selected_poll_name"])
|
|
|
38 |
|
39 |
def delete_poll():
|
40 |
utils.load_polls().remove(utils.find_poll(st.session_state["selected_poll_name"]))
|
41 |
+
st.query_params.pop("poll")
|
42 |
del st.session_state["selected_poll_name"]
|
43 |
|
44 |
|
|
|
70 |
st.button("Clear Votes", on_click=clear_votes_section, use_container_width=True)
|
71 |
st.button("Delete Poll", on_click=delete_poll, use_container_width=True)
|
72 |
|
73 |
+
def show_qrcode():
|
74 |
+
selected_poll_name = st.session_state["selected_poll_name"]
|
75 |
+
columns = st.columns(5)
|
76 |
+
with columns[2]:
|
77 |
+
st.image(utils.generate_qr_code_image_link(selected_poll_name))
|
78 |
+
|
79 |
def load():
|
80 |
selected_poll_name = st.session_state["selected_poll_name"]
|
81 |
+
st.write("")
|
82 |
columns = st.columns(3)
|
83 |
with columns[0]:
|
84 |
+
st.button("Exit", on_click=exit_poll, use_container_width=True)
|
85 |
with columns[1]:
|
86 |
+
st.button("Refresh", use_container_width=True)
|
87 |
with columns[2]:
|
88 |
+
st.link_button("Link To Poll", "?poll="+selected_poll_name, type="primary", use_container_width=True)
|
89 |
+
|
90 |
st.title(selected_poll_name)
|
91 |
if not is_admin():
|
92 |
load_voting()
|
93 |
else:
|
94 |
+
load_votes()
|
95 |
+
|
96 |
+
|
97 |
+
show_qrcode()
|
utils.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import uuid
|
|
|
|
|
3 |
|
4 |
|
5 |
@st.cache_resource
|
@@ -27,3 +29,33 @@ def get_options():
|
|
27 |
"Missed a Point",
|
28 |
"Need a brake",
|
29 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import uuid
|
3 |
+
import os
|
4 |
+
import streamlit.components.v1 as components
|
5 |
|
6 |
|
7 |
@st.cache_resource
|
|
|
29 |
"Missed a Point",
|
30 |
"Need a brake",
|
31 |
]
|
32 |
+
|
33 |
+
|
34 |
+
def get_base_url():
|
35 |
+
return os.getenv("BASE_URL", default="https://example.com")
|
36 |
+
|
37 |
+
|
38 |
+
def generate_qr_code_image_link(poll_name):
|
39 |
+
link = f"https://quickchart.io/qr?text={get_base_url()}%2F%3Fpoll%3D{poll_name}&ecLevel=Q&size=1000&format=svg"
|
40 |
+
return link
|
41 |
+
|
42 |
+
|
43 |
+
def statistics():
|
44 |
+
st.write("---")
|
45 |
+
columns = st.columns(5)
|
46 |
+
with columns[2]:
|
47 |
+
components.html(
|
48 |
+
""" <!-- Histats.com (div with counter) --><div id="histats_counter"></div>
|
49 |
+
<!-- Histats.com START (aync)-->
|
50 |
+
<script type="text/javascript">var _Hasync= _Hasync|| [];
|
51 |
+
_Hasync.push(['Histats.start', '1,4880407,4,9,110,60,00011111']);
|
52 |
+
_Hasync.push(['Histats.fasi', '1']);
|
53 |
+
_Hasync.push(['Histats.track_hits', '']);
|
54 |
+
(function() {
|
55 |
+
var hs = document.createElement('script'); hs.type = 'text/javascript'; hs.async = true;
|
56 |
+
hs.src = ('//s10.histats.com/js15_as.js');
|
57 |
+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(hs);
|
58 |
+
})();</script>
|
59 |
+
<noscript><a href="/" target="_blank"><img src="//sstatic1.histats.com/0.gif?4880407&101" alt="hidden hit counter" border="0"></a></noscript>
|
60 |
+
<!-- Histats.com END -->"""
|
61 |
+
)
|