This repository was archived by the owner on Jul 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathguestbook.py
More file actions
71 lines (60 loc) · 2.54 KB
/
guestbook.py
File metadata and controls
71 lines (60 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import re
import datetime
import streamlit as st
import pandas as pd
import requests
from sheet_manager import sheet_manager
from sheet_manager import servsecrets
def post_to_webhook(message):
url = os.environ.get("WEBHOOK_URL", "https://example.com") or "https://example.com"
data = {"content": message}
params = {"thread_id": os.environ.get("WEBHOOK_THREAD_ID", "0") or "0"}
result = requests.post(url, json=data, params=params, timeout=2048)
try:
result.raise_for_status()
except requests.exceptions.HTTPError as err:
return Exception(err)
else:
print(f'Payload delivered successfully, code {result.status_code}.')
st.set_page_config(page_title="osu! booth Guestbook",
page_icon=":heart:", initial_sidebar_state="collapsed")
# HACK: This is to get rid of the sidebar
no_sidebar_style = """
<style>
div[data-testid="stSidebarNav"] {display: none;}
</style>
"""
st.markdown(no_sidebar_style, unsafe_allow_html=True)
# Get header
with open("GUESTBOOK_HEADER.md", "r", encoding="utf-8") as f:
st.markdown(f.read(), unsafe_allow_html=True)
# Begin Guestbook Entrypoint
with st.form('guestbook', clear_on_submit=True):
is_osu_user = st.checkbox("Are you an osu! player?")
name = st.text_input("Your Name (doesn't have to be your real name)")
days_attending = st.selectbox("What Day are you attending?",
["Day 1", "Day 2", "Day 3", "All Days"])
message = st.text_area("Leave a message for us!")
if st.form_submit_button("Submit"):
manager = sheet_manager.SheetManager(
creds=servsecrets.service_acct_creds,
sheets_key=st.secrets.GSheets.guestbook_sheets_key
)
data_dict = {
'is_osu_user': [is_osu_user],
'name': [name],
'days_attending': [days_attending],
'message': [message],
'ts': [str(datetime.datetime.now())]
}
# Alert if someone special is here
if re.match(r'[VvIiNnCcEeNnTt]*[\d]{4}', name) is not None or re.match(r'[TtoKkIiIiWwAa]{7}', name) is not None:
# Fire the silent alarm
post_to_webhook(
f"## :rotating_light: ALERT: Possible bad actor detected in Guestbook! ({name})")
# The sheets must have 4 column names (as per keys in data_dict)
# that was made before pushing
manager.push_data(sheet_number=0, data=pd.DataFrame(data_dict))
st.success(f'Thanks for signing to the Guestbook, {name}!')
# End Guestbook Entrypoint