def team(name: str): name = escape(name or "") team_object = Team(name) if not team_object.exists: return abort(404) return render_template("team.html", title=name, team=team_object)
def leave(): team = current_user["team"] if team == "Solo": return previous_team = Team(team) previous_members = previous_team["members"] previous_members.remove(current_user.username) if len(previous_members) < 1: previous_team.database.document(team).delete() else: previous_team.update(members=previous_members or []) current_user.update(team="Solo") return render_template("team.html", title="Solo", team=Team("Solo"))
def listTeams(self): if config.debugLevelEnabled(config.TRACE): print 'ServerProxy: Sending listTeams request' response = self.socket.sendExpectListResponse('teams') if config.debugLevelEnabled(config.TRACE): print 'ServerProxy: Response for listTeams request = {0}'.format(response) return Team.parseList(response.getList())
def listTeams(self): if config.debugLevelEnabled(config.TRACE): print 'ServerProxy: Sending listTeams request' response = self.socket.sendExpectListResponse('teams') if config.debugLevelEnabled(config.TRACE): print 'ServerProxy: Response for listTeams request = {0}'.format( response) return Team.parseList(response.getList())
def __init__(self, overview, data): time_format = data.config.time_format linescore = overview.linescore away = linescore.teams.away home = linescore.teams.home away_abbrev = data.teams_info[away.team.id].abbreviation home_abbrev = data.teams_info[home.team.id].abbreviation self.away_team = Team(away.team.id, away_abbrev, away.team.name, away.goals, away.shotsOnGoal, away.powerPlay, away.numSkaters, away.goaliePulled) self.home_team = Team(home.team.id, home_abbrev, home.team.name, home.goals, home.shotsOnGoal, home.powerPlay, home.numSkaters, home.goaliePulled) self.date = convert_time(overview.game_date).strftime("%Y-%m-%d") self.start_time = convert_time( overview.game_date).strftime(time_format) self.status = overview.status self.periods = Periods(overview) self.intermission = linescore.intermissionInfo.inIntermission if data.status.is_final(overview.status): self.winning_team = overview.w_team self.loosing_team = overview.l_team
import hashlib, datetime, requests from flask import Blueprint, render_template, request, redirect, url_for, flash from flask_login import current_user, login_user, login_required, logout_user from validate_email import validate_email from markupsafe import escape from typing import Union from name import Checker from data.user import User from data.team import Team auth = Blueprint("auth", __name__) hash_password = lambda p: hashlib.sha3_384(p.encode()).hexdigest() solo_team = Team("Solo") def check_password(user_object, password: str): if not user_object.exists: return False return user_object["password"] == hash_password(password) def logCaptcha(result: Union[str, bool]): if isinstance(result, bool): return try: requests.post("https://www.google.com/recaptcha/api/siteverify", data={ "secret": "6LeUQ_wZAAAAAPn3LFgBprWlUsjvextIQqY3FHnq",
def render(self): for team_id in self.preferred_teams: self.team_id = team_id team = self.teams_info[team_id] team_data = Team(team.team_id, team.abbreviation, team.name) team_colors = self.data.config.team_colors bg_color = team_colors.color("{}.primary".format(team_id)) txt_color = team_colors.color("{}.text".format(team_id)) prev_game = team.previous_game next_game = team.next_game logo_renderer = LogoRenderer(self.matrix, self.data.config, self.layout.logo, team_data, 'team_summary') try: if prev_game: prev_game_id = self.teams_info[ team_id].previous_game.dates[0]["games"][0]["gamePk"] prev_game_scoreboard = Scoreboard( nhl_api.overview(prev_game_id), self.data) else: prev_game_scoreboard = False self.data.network_issues = False except ValueError: prev_game_scoreboard = False self.data.network_issues = True try: if next_game: next_game_id = self.teams_info[team_id].next_game.dates[0][ "games"][0]["gamePk"] next_game_scoreboard = Scoreboard( nhl_api.overview(next_game_id), self.data) else: next_game_scoreboard = False self.data.network_issues = False except ValueError: next_game_scoreboard = False self.data.network_issues = True stats = team.stats im_height = 67 team_abbrev = team.abbreviation team_logo = Image.open( get_file('assets/logos/{}.png'.format(team_abbrev))) i = 0 if not self.sleepEvent.is_set(): image = self.draw_team_summary(stats, prev_game_scoreboard, next_game_scoreboard, bg_color, txt_color, im_height) self.matrix.clear() logo_renderer.render() self.matrix.draw_image_layout( self.layout.info, image, ) self.matrix.render() if self.data.network_issues: self.matrix.network_issue_indicator() self.sleepEvent.wait(5) # Move the image up until we hit the bottom. while i > -(im_height - self.matrix.height) and not self.sleepEvent.is_set(): i -= 1 self.matrix.clear() logo_renderer.render() self.matrix.draw_image_layout(self.layout.info, image, (0, i)) self.matrix.render() if self.data.network_issues: self.matrix.network_issue_indicator() self.sleepEvent.wait(0.3) # Show the bottom before we change to the next table. self.sleepEvent.wait(5)
def add_team(self, team_id, full_name, abbr, nick_name, city): if team_id not in self.db_team: self.db_team[team_id] = Team(team_id, full_name, abbr, nick_name, city) else: print(f"{team_id} is already in the database!")
def create(): team_name = escape(request.form.get("name", "Solo")) password = escape(request.form.get("password", "")) captcha = request.form.get("g-recaptcha-response", False) if not request.form.get("rules", False): flash("Please accept the rules.") return render_template("join.html", title="Join Team", team_name=team_name, password=password, teams=Team("placeholder").database.stream()) logCaptcha(captcha) if not captcha: flash("Please complete the reCAPTCHA.") return render_template("join.html", title="Join Team", team_name=team_name, password=password, teams=Team("placeholder").database.stream()) if password == "": flash("Invalid password provided.") return render_template("join.html", title="Join Team", team_name=team_name, teams=Team("placeholder").database.stream()) team_object = Team(team_name) if team_object.exists or team_object.name == "Solo": flash("Team name already in use.") return render_template("join.html", title="Join Team", password=password, teams=Team("placeholder").database.stream()) if not Checker(team_name).is_valid: flash("Team name not allowed.") return render_template("join.html", title="Join Team", password=password, teams=Team("placeholder").database.stream()) previous_team = Team(current_user["team"]) previous_members = previous_team["members"] try: previous_members.remove(current_user.username) except: pass if len(previous_members) < 1 and previous_team.name != "Solo": previous_team.database.document(previous_team.name).delete() else: previous_team.update(members=previous_members or []) User(current_user.username).update(team=team_name) team_object.update( join_code=hash_password(password), members=[current_user.username], submitted=False, ) session["team_name"] = "" session["open_join"] = False return redirect(f"/team/{team_name}")
def join(): if request.method == "GET": return render_template("join.html", title="Join Team", team_name=session.get("team_name", ""), open_join=session.get("open_join", False), teams=Team("placeholder").database.stream()) team_name = escape(request.form.get("team_name", "")) join_code = escape(request.form.get("join_code", "")) captcha = request.form.get("g-recaptcha-response", False) team_object = Team(team_name) if not request.form.get("rules", False): session["open_join"] = True session["team_name"] = team_name flash("Please accept the rules.") return redirect(url_for("main.join")) logCaptcha(captcha) if not captcha: session["open_join"] = True session["team_name"] = team_name flash("Please complete the captcha.") return redirect(url_for("main.join")) if not team_object.exists: session["open_join"] = True session["team_name"] = team_name flash("Unable to get team object.") return redirect(url_for("main.join")) if team_name == User(current_user.username)["team"]: session["open_join"] = True session["team_name"] = team_name flash("You are already a member of this team.") return redirect(url_for("main.join")) if team_object["join_code"] != hash_password(join_code): session["open_join"] = True session["team_name"] = team_name flash("Incorrect join code provided.") return redirect(url_for("main.join")) previous_team = Team(current_user["team"]) previous_members = previous_team["members"] try: previous_members.remove(current_user.username) except: pass if len(previous_members) < 1 and previous_team.name != "Solo": previous_team.database.document(previous_team.name).delete() else: previous_team.update(members=previous_members or []) current_members = team_object["members"] current_members.append(current_user.username) team_object.update(members=current_members) current_user.update(team=team_name) session["team_name"] = "" session["open_join"] = False return redirect(f"/team/{team_name}")