Initial commit
This commit is contained in:
47
website/helpers.py
Normal file
47
website/helpers.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import logging
|
||||
import os
|
||||
from markupsafe import escape
|
||||
from pathlib import Path
|
||||
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:
|
||||
return time.time() - os.path.getmtime(fname)
|
||||
|
||||
|
||||
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) 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
|
||||
Reference in New Issue
Block a user