Compare commits

...

5 Commits

Author SHA1 Message Date
Nate Bowman
ee794515de Parse users better 2026-10-08 19:57:28 -04:00
Nate Bowman
5c30b91cb9 Fix case where downloaded files do not exist 2026-10-08 18:37:47 -04:00
Nate Bowman
f5b58cfe58 Use absolute path to curl
The process was not finding curl when launched via Supervisor
2026-10-08 18:36:48 -04:00
Nate Bowman
5e0a74f8ce Check output for curl commands 2026-10-08 18:36:32 -04:00
Nate Bowman
17ccd0bab7 Rename example config
This way, it will not conflict with an actual config file.
2026-10-08 18:34:26 -04:00
4 changed files with 26 additions and 12 deletions

View File

@@ -43,7 +43,7 @@ def password_form():
# The HTML form asking for password # The HTML form asking for password
return '''<form method="post" id="form"> return '''<form method="post" id="form">
<label for="names" form="form">Which users do you want? <label for="names" form="form">Which users do you want?
(Hint: lowercase, comma-separated) (comma-separated)
</label> </label>
<br> <br>
<input type="text" id="names" name="names" required> <input type="text" id="names" name="names" required>

View File

@@ -1,7 +1,6 @@
import json import json
import logging import logging
import pandas as pd import pandas as pd
import subprocess
from website import helpers from website import helpers
@@ -12,14 +11,13 @@ logger = logging.getLogger(__name__)
def _download_max_players() -> None: def _download_max_players() -> None:
# be sure to use single quotes within the command to prevent shell escaping # be sure to use single quotes within the command to prevent shell escaping
cmd = ( cmd = (
f"curl -s" f"/usr/bin/curl -s"
f" -u 'anonymous:{config.share['password']}'" f" -u 'anonymous:{config.share['password']}'"
f" -o '{config.max_player_spreadsheet_path}'" f" -o '{config.max_player_spreadsheet_path}'"
f" '{config.share['uri']}'" f" '{config.share['uri']}'"
) )
# TODO error check helpers.run_and_log_cmd(cmd)
subprocess.run(cmd, shell=True)
def _download_games(user: str) -> None: def _download_games(user: str) -> None:
@@ -30,19 +28,20 @@ def _download_games(user: str) -> None:
# be sure to use single quotes within the command to prevent shell escaping # be sure to use single quotes within the command to prevent shell escaping
cmd = ( cmd = (
f"curl {CURL_OPTIONS} '{STEAM_API_URI}" f"/usr/bin/curl {CURL_OPTIONS} '{STEAM_API_URI}"
f"?key={config.key}" f"?key={config.key}"
f"{STEAM_OPTIONS}" f"{STEAM_OPTIONS}"
f"&steamid={config.users[user]}'" f"&steamid={config.users[user]}'"
) )
# TODO error check
subprocess.run(cmd, shell=True) helpers.run_and_log_cmd(cmd)
def _refresh_games_if_needed(users: list(str), force=False) -> None: def _refresh_games_if_needed(users: list(str), force=False) -> None:
for u in users: for u in users:
path = helpers.get_user_fname(u) path = helpers.get_user_fname(u)
if force or helpers.get_file_age(path) > config.user_games_refresh_delay_seconds: age = helpers.get_file_age(path)
if force or not age or age > config.user_games_refresh_delay_seconds:
logger.info(f'Downloading {path}') logger.info(f'Downloading {path}')
_download_games(u) _download_games(u)
else: else:
@@ -72,7 +71,8 @@ def get_games_from_steam(users: list(str), force=False) -> pd.DataFrame:
def get_max_players_data(force=False) -> pd.DataFrame: def get_max_players_data(force=False) -> pd.DataFrame:
# freshen up max players list if needed # freshen up max players list if needed
path = config.max_player_spreadsheet_path path = config.max_player_spreadsheet_path
if force or helpers.get_file_age(path) > config.max_players_refresh_delay_seconds: age = helpers.get_file_age(path)
if force or not age or age > config.max_players_refresh_delay_seconds:
logger.info(f'Downloading {path}') logger.info(f'Downloading {path}')
_download_max_players() _download_max_players()
else: else:

View File

@@ -2,6 +2,7 @@ import logging
import os import os
from markupsafe import escape from markupsafe import escape
from pathlib import Path from pathlib import Path
import subprocess
import time import time
from website.config import config from website.config import config
@@ -14,7 +15,11 @@ def get_user_fname(user: str) -> str:
def get_file_age(fname: Path) -> int: def get_file_age(fname: Path) -> int:
return time.time() - os.path.getmtime(fname) try:
age = time.time() - os.path.getmtime(fname)
except FileNotFoundError:
age = None
return age
def check_max_players_list() -> None: def check_max_players_list() -> None:
@@ -37,7 +42,7 @@ def check_max_players_list() -> None:
def safely_get_people(unsafe_people: str) -> list(str): def safely_get_people(unsafe_people: str) -> list(str):
safe_users = [escape(u) for u in unsafe_people.split(',')] safe_users = [escape(u.strip().lower()) for u in unsafe_people.split(',')]
for u in safe_users: for u in safe_users:
if u not in config.users.keys(): if u not in config.users.keys():
@@ -45,3 +50,12 @@ def safely_get_people(unsafe_people: str) -> list(str):
return None return None
return safe_users return safe_users
def run_and_log_cmd(cmd):
proc = subprocess.run(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
if proc.returncode != 0:
logger.error(proc.stdout)