Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -153,11 +153,79 @@ dict_pitch_name_tp.update({'4-Seam':'#FF007D50'})
|
|
| 153 |
# Sort dict_pitch alphabetically by pitch name
|
| 154 |
dict_pitch_alpha = dict(sorted(dict_pitch.items(), key=lambda item: item[1]))
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
from shiny import App, reactive, ui, render
|
| 157 |
from shiny.ui import h2, tags
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
# Define the UI layout for the app
|
| 160 |
-
|
| 161 |
ui.layout_sidebar(
|
| 162 |
ui.panel_sidebar(
|
| 163 |
# Row for selecting season and level
|
|
@@ -365,9 +433,44 @@ ui.card(
|
|
| 365 |
)
|
| 366 |
)
|
| 367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
def server(input, output, session):
|
| 369 |
# This code should be inserted in your server function
|
| 370 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
# Add this near the top of the server function
|
| 372 |
modified_data = reactive.value(None)
|
| 373 |
# Add a reactive value to store the current selection state
|
|
|
|
| 153 |
# Sort dict_pitch alphabetically by pitch name
|
| 154 |
dict_pitch_alpha = dict(sorted(dict_pitch.items(), key=lambda item: item[1]))
|
| 155 |
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
import requests
|
| 159 |
+
|
| 160 |
+
import os
|
| 161 |
+
CAMPAIGN_ID = os.getenv("CAMPAIGN_ID")
|
| 162 |
+
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN")
|
| 163 |
+
BACKUP_PW = os.getenv("BACKUP_PW")
|
| 164 |
+
ADMIN_PW = os.getenv("ADMIN_PW")
|
| 165 |
+
|
| 166 |
+
url = f"https://www.patreon.com/api/oauth2/v2/campaigns/{CAMPAIGN_ID}/members"
|
| 167 |
+
|
| 168 |
+
headers = {
|
| 169 |
+
"Authorization": f"Bearer {ACCESS_TOKEN}"
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
# Simple parameters, requesting the member's email and currently entitled tiers
|
| 173 |
+
params = {
|
| 174 |
+
"fields[member]": "full_name,email", # Request the member's email
|
| 175 |
+
"include": "currently_entitled_tiers", # Include the currently entitled tiers
|
| 176 |
+
"page[size]": 1000 # Fetch up to 1000 patrons per request
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
response = requests.get(url, headers=headers, params=params)
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
VALID_PASSWORDS = []
|
| 183 |
+
if response.status_code == 200:
|
| 184 |
+
data = response.json()
|
| 185 |
+
for patron in data['data']:
|
| 186 |
+
try:
|
| 187 |
+
tiers = patron['relationships']['currently_entitled_tiers']['data']
|
| 188 |
+
if any(tier['id'] == '9078921' for tier in tiers):
|
| 189 |
+
full_name = patron['attributes']['email']
|
| 190 |
+
VALID_PASSWORDS.append(full_name)
|
| 191 |
+
except KeyError:
|
| 192 |
+
continue
|
| 193 |
+
VALID_PASSWORDS.append(BACKUP_PW)
|
| 194 |
+
VALID_PASSWORDS.append(ADMIN_PW)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
from shiny import App, reactive, ui, render
|
| 198 |
from shiny.ui import h2, tags
|
| 199 |
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
# Define the login UI
|
| 203 |
+
login_ui = ui.page_fluid(
|
| 204 |
+
ui.card(
|
| 205 |
+
ui.h2([
|
| 206 |
+
"TJStats Daily Pitching Summary App ",
|
| 207 |
+
ui.tags.a("(@TJStats)", href="https://twitter.com/TJStats", target="_blank")
|
| 208 |
+
]),
|
| 209 |
+
ui.p(
|
| 210 |
+
"This App is available to Superstar Patrons. Please enter your Patreon email address in the box below. If you're having trouble, please refer to the ",
|
| 211 |
+
ui.tags.a("Patreon post", href="https://www.patreon.com/posts/122860440", target="_blank"),
|
| 212 |
+
"."
|
| 213 |
+
),
|
| 214 |
+
ui.input_password("password", "Enter Patreon Email (or Password from Link):", width="25%"),
|
| 215 |
+
ui.tags.input(
|
| 216 |
+
type="checkbox",
|
| 217 |
+
id="authenticated",
|
| 218 |
+
value=False,
|
| 219 |
+
disabled=True
|
| 220 |
+
),
|
| 221 |
+
ui.input_action_button("login", "Login", class_="btn-primary"),
|
| 222 |
+
ui.output_text("login_message"),
|
| 223 |
+
)
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
# Define the UI layout for the app
|
| 228 |
+
main_ui = ui.page_fluid(
|
| 229 |
ui.layout_sidebar(
|
| 230 |
ui.panel_sidebar(
|
| 231 |
# Row for selecting season and level
|
|
|
|
| 433 |
)
|
| 434 |
)
|
| 435 |
|
| 436 |
+
# Combined UI with conditional panel
|
| 437 |
+
app_ui = ui.page_fluid(
|
| 438 |
+
ui.tags.head(
|
| 439 |
+
ui.tags.script(src="script.js")
|
| 440 |
+
),
|
| 441 |
+
|
| 442 |
+
ui.panel_conditional(
|
| 443 |
+
"!input.authenticated",
|
| 444 |
+
login_ui
|
| 445 |
+
),
|
| 446 |
+
ui.panel_conditional(
|
| 447 |
+
"input.authenticated",
|
| 448 |
+
main_ui
|
| 449 |
+
)
|
| 450 |
+
)
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
|
| 454 |
def server(input, output, session):
|
| 455 |
# This code should be inserted in your server function
|
| 456 |
|
| 457 |
+
@reactive.Effect
|
| 458 |
+
@reactive.event(input.login)
|
| 459 |
+
def check_password():
|
| 460 |
+
if input.password() in VALID_PASSWORDS:
|
| 461 |
+
ui.update_checkbox("authenticated", value=True)
|
| 462 |
+
ui.update_text("login_message", value="")
|
| 463 |
+
else:
|
| 464 |
+
ui.update_text("login_message", value="Invalid password!")
|
| 465 |
+
ui.update_text("password", value="")
|
| 466 |
+
|
| 467 |
+
@output
|
| 468 |
+
@render.text
|
| 469 |
+
def login_message():
|
| 470 |
+
return ""
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
|
| 474 |
# Add this near the top of the server function
|
| 475 |
modified_data = reactive.value(None)
|
| 476 |
# Add a reactive value to store the current selection state
|