import logging import os from markupsafe import escape from pathlib import Path import subprocess import time from website.config import config logger = logging.getLogger(__name__) def get_user_fname(user: str) -> str: return config.resources / f'{user}.json' def get_file_age(fname: Path) -> int: try: age = time.time() - os.path.getmtime(fname) except FileNotFoundError: age = None return age def check_max_players_list() -> None: people = list(config.users.keys()) dfg = get_games_from_steam(people) dfp = get_max_players_data() oops = dfp.index[~dfp.index.isin(dfg.index)] oops = '\n'.join(sorted(oops.to_list())) logger.info( 'The following titles are in the max-players spreadsheet but' ' are not in any user lists:\n' f'{oops}\n' 'This may mean that they are misspelled in the spreadsheet.' 'It is also possible that they are not Steam games or that' ' they are Steam games that nobody owns.' ) def safely_get_people(unsafe_people: str) -> list(str): safe_users = [escape(u.strip().lower()) for u in unsafe_people.split(',')] for u in safe_users: if u not in config.users.keys(): logger.warn(f'Requested user {u} is not in the configuration file') return None 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)