def send_reminder():
        reminder_days_before_game = 4

        if (Game.get_next_game().date.date() - datetime.datetime.now().date()
            ).days == reminder_days_before_game:
            if os.environ.get("environment") in ['QA', 'DEV']:
                email_to = '*****@*****.**'
            else:
                email_to = UserGame.get_reminder_user_list()

            next_game = Game.get_next_game()

            template = jinja2.Template(UserGameConstants.templateHtml)
            html = template.render(next_game=next_game,
                                   deadline=next_game.date -
                                   datetime.timedelta(days=3),
                                   opponent=next_game.get_opponent())

            response = requests.post(
                UserGameConstants.URL,
                auth=('api', UserGameConstants.API_KEY),
                data={
                    "from":
                    UserGameConstants.FROM,
                    "to":
                    UserGameConstants.FROM,
                    "bcc":
                    email_to,
                    "subject":
                    "Friendly Reminder to Submit Scores for {} Game".format(
                        next_game.get_opponent()),
                    "html":
                    html
                })
            response.raise_for_status()
 def __init__(self,
              user,
              game,
              game_date,
              attendance,
              home_score,
              away_score,
              score_updated_on=None,
              home_points=0,
              away_points=0,
              total_points=0,
              points_updated_on=None,
              admin_enter=None,
              _id=None):
     self.user = User.get_user_by_id(user['_id'])
     self.game = Game.get_game_by_id(game)
     self.game_date = Game.get_game_by_id(game).date
     self.attendance = attendance
     self.home_score = home_score
     self.away_score = away_score
     self.score_updated_on = score_updated_on
     self.home_points = home_points
     self.away_points = away_points
     self.total_points = total_points
     self.points_updated_on = points_updated_on
     self.admin_enter = admin_enter
     self._id = uuid.uuid4().hex if _id is None else _id
Beispiel #3
0
def get_leaderboard():
    """
    This function will get all games up to and including the game that is selected for the leaderboard.  The
    function receives the game._id of the game to be viewed and a dict is built to sum up the total of points
    accumulated by each user

    :return: leaderboard template with unzipped lists of leaders and the totals, as well as the user game details
    for the game passed into the function and pass through of the game id
    """

    games_prior = Game.get_all_prior_games_in_current_year()
    if games_prior:
        if request.method == 'GET':
            max_game = games_prior[0]
        elif request.method == 'POST':
            max_game = Game.get_game_by_id(request.form['game_view'])

        user_games_prior = UserGame.get_all_prior_games_in_current_year(max_game.game_num)
        user_totals = defaultdict(int)
        for ug in user_games_prior:
            user_totals[ug.user._id] += ug.total_points
        user_totals_sorted = sorted(user_totals.items(), key=operator.itemgetter(1), reverse=True)
        leaders = [x[0] for x in user_totals_sorted]
        points = [x[1] for x in user_totals_sorted]
        latest_user_games = UserGame.get_attendance_by_game(max_game._id)
        return render_template("user_games/leaderboard.jinja2", leaders=leaders, points=points,
                               latest_user_games=latest_user_games, games_prior=games_prior, max_game=max_game)
    else:
        return render_template("user_games/no_games_played.jinja2")
Beispiel #4
0
def edit_game(game_id):
    if request.method == 'POST':
        game = Game.get_game_by_id(game_id)
        game.location = Location.get_location_by_id(request.form['location'])
        game.stadium = request.form['stadium']
        game.hht_theme = request.form['hht_theme']
        game.save_to_mongo()

    game = Game.get_game_by_id(game_id)
    teams = Team.get_teams()
    locations = Location.get_all_locations()
    stadiums = Game.get_all_stadiums()
    stadiums.sort()

    return render_template("games/edit_game.jinja2",
                           teams=teams,
                           game=game,
                           locations=locations,
                           stadiums=stadiums)
Beispiel #5
0
 def __init__(self,
              game,
              player,
              attendance='Und',
              beverages='No',
              _id=None):
     self.game = Game.get_game_by_id(game)
     self.player = Player.get_player_by_id(player['_id'])
     self.attendance = attendance
     self.beverages = beverages
     self._id = uuid.uuid4().hex if _id is None else _id
Beispiel #6
0
 def user_default_values():
     alerts = {}
     for a in AlertConstants.ALERTS:
         alerts[a] = 'On'
     attendance = {}
     games = Game.get_games_by_year(Year.get_current_year()._id)
     for i in games:
         if i.location.city == 'Blacksburg':
             attendance[i.game_num] = 'Yes'
         else:
             attendance[i.game_num] = 'No'
     return alerts, attendance
Beispiel #7
0
    def update_games():
        # this is used to find the id within the href of the time element on the schedule
        find_str = 'games'

        link = "https://richmondskating.ezleagues.ezfacility.com/teams/2200008/Coach-Potatoes.aspx"
        request = requests.get(link)
        content = request.content

        soup = BeautifulSoup(content, "html.parser")

        schedule = soup.find("table", {"id": "ctl00_C_Schedule1_GridView1"})

        schedule_rows = schedule.find_all(
            "tr", {"class": ["RowStyle", "AlternateRowStyle"]})

        for sr in schedule_rows:
            game_info = sr.find_all("td")
            date = game_info[0].a.text
            home_team = game_info[1].a.text
            away_team = game_info[3].a.text
            time = game_info[4].a.text
            venue = game_info[5].a.text
            id = game_info[4].a['href']

            # 8 digit number after "games/" is used as id for game
            slice_id = id[id.find(find_str) + 6:id.find(find_str) + 14]
            game = Database.find_one('games', {"_id": slice_id})
            if game is None:
                new_game = Game(date, time, venue, home_team, away_team,
                                slice_id)
                new_game.save_to_mongo()
                Attendance.build_for_new_game(new_game._id)
            else:
                game = Game.get_game_by_id(slice_id)
                game.date = date
                game.home_team = home_team
                game.away_team = away_team
                game.time = time
                game.venue = venue
                game.save_to_mongo()
 def __init__(self,
              game,
              author,
              preview,
              created_on,
              updated_on=None,
              _id=None):
     self.game = Game.get_game_by_id(game)
     self.author = User.get_user_by_id(author)
     self.preview = preview
     self.created_on = created_on
     self.updated_on = updated_on
     self._id = uuid.uuid4().hex if _id is None else _id
Beispiel #9
0
def create_game():
    if request.method == 'POST':
        new_game = Game(game_num=request.form['game_num'],
                        away_team=request.form['away_team'],
                        home_team=request.form['home_team'],
                        year=request.form['year'],
                        location=Location.get_location_by_id(
                            request.form['location']).json(),
                        stadium=request.form['stadium'],
                        date=datetime.strptime(request.form['date'],
                                               "%m/%d/%Y"))
        new_game.save_to_mongo()
        users = User.get_all_users()
        if new_game.location.city == 'Blacksburg':
            attendance = 'Yes'
        else:
            attendance = 'No'
        for u in users:
            UserGame(user=u.json(),
                     game=new_game._id,
                     attendance=attendance,
                     game_date=None,
                     home_score=0,
                     away_score=0).save_to_mongo()

    years = Year.get_all_years()
    teams = Team.get_teams()
    locations = Location.get_all_locations()
    stadiums = Game.get_all_stadiums()
    stadiums.sort()

    return render_template("games/create_game.jinja2",
                           teams=teams,
                           locations=locations,
                           stadiums=stadiums,
                           years=years)
Beispiel #10
0
def new_user():
    """

    :return:
    """
    if request.method == 'POST':
        email = request.form['email']
        try:
            if User.new_user_valid(email, request.form['pword'], request.form['confirmpword']):
                fname = request.form['fname']
                lname = request.form['lname']
                pword = Utils.hash_password(request.form['pword'])
                phone = request.form['phone']
                location = request.form['location']
                if User.check_offline_user_exist(email) is not None:
                    user = User.get_user_by_email(email)
                    user.f_name = fname
                    user.l_name = lname
                    user.password = pword
                    user.admin_created = 'No'
                    user.prognosticator = 'Yes'
                    user.admin = 'No'
                    user.phone = phone
                    user.location = location
                    user.created_on = datetime.datetime.utcnow()
                    user.save_to_mongo()

                else:
                    user = User(fname, lname, email, pword, phone=phone, location=location,
                                created_on=datetime.datetime.utcnow())
                    user.save_to_mongo()

                    alerts, attendance = User.user_default_values()
                    for alert in alerts:
                        Alert(user=user._id, alert=alert, yes_no='On').save_to_mongo()
                    for na in attendance:
                        UserGame(user=user.json(),
                                 game=Game.get_game_by_num(na, Year.get_current_year()._id)._id,
                                 attendance=attendance[na], home_score=0,
                                 away_score=0, game_date=0).save_to_mongo()

                session['user'] = user._id
                session['useradmin'] = user.admin
                return redirect(url_for('alerts.manage_alerts'))
        except UserErrors.UserError as e:
            return render_template("users/new_user.jinja2", error=e.message)
    else:
        return render_template("users/new_user.jinja2")
 def __init__(self,
              user,
              number,
              section,
              seats,
              game,
              sold_flag=None,
              price=None,
              _id=None):
     self.user = User.get_user_by_id(user)
     self.number = number
     self.section = section
     self.seats = seats
     self.game = Game.get_game_by_id(game)
     self.sold_flag = sold_flag
     self.price = None if price is None else float(price)
     self._id = uuid.uuid4().hex if _id is None else _id
Beispiel #12
0
def detail(game_id):
    user = session['user']

    this_game = Game.get_game_by_id(game_id)
    # format the date for the detail screen
    this_game.date = this_game.date.strftime('%B %d')

    # getting attendance for each type to pass along to template
    yes_attendance = UserGame.get_attendance_by_game_and_status(game_id, 'Yes')
    maybe_attendance = UserGame.get_attendance_by_game_and_status(
        game_id, 'Maybe')
    no_attendance = UserGame.get_attendance_by_game_and_status(game_id, 'No')

    # get preview for game
    preview = Preview.get_preview_by_game(game_id)

    # get food for game
    food_for_game = Food.get_food_by_game(game_id)

    # get have_tickets for game
    have_tickets_for_game = HaveTicket.get_havetickets_by_game(game_id)

    # get want_tickets for game
    want_tickets_for_game = WantTicket.get_wanttickets_by_game(game_id)

    # get convo for game
    convos = GameConversation.get_convo_by_game(game_id)

    return render_template("games/game_detail.jinja2",
                           game=this_game,
                           preview=preview,
                           yes_attendance=yes_attendance,
                           maybe_attendance=maybe_attendance,
                           no_attendance=no_attendance,
                           food_for_game=food_for_game,
                           have_tickets_for_game=have_tickets_for_game,
                           want_tickets_for_game=want_tickets_for_game,
                           convos=convos,
                           user=user,
                           DoD=(date.today() - date(2004, 11, 28)).days)
Beispiel #13
0
def user_administration():
    if request.method == 'POST':
        user = User(f_name=request.form['fname'],
                    l_name=request.form['lname'],
                    email=request.form['email'],
                    prognosticator=request.form['prognosticator'],
                    admin_created='Yes'
                    )
        alerts, attendance = User.user_default_values()
        user.insert_new_user()

        for alert in alerts:
            new_alert = Alert(user._id, alert, alerts[alert])
            new_alert.save_to_mongo()
        for na in attendance:
            new_attendance = UserGame(user=user.json(),
                                      game=Game.get_game_by_num(na, Year.get_current_year()._id)._id,
                                      attendance=attendance[na], home_score=0,
                                      away_score=0, game_date=0)
            new_attendance.save_to_mongo()
    users = User.get_all_users()
    return render_template('users/admin_dashboard.jinja2', users=users)
    def send(self):
        if os.environ.get("environment") in ['QA', 'DEV']:
            email_to = '[email protected],[email protected]'
        else:
            email_to = self.get_preview_user_list()

        next_game = Game.get_next_game()

        response = requests.post(PreviewConstants.URL,
                                 auth=('api', PreviewConstants.API_KEY),
                                 data={
                                     "from":
                                     PreviewConstants.FROM,
                                     "to":
                                     PreviewConstants.FROM,
                                     "bcc":
                                     email_to,
                                     "subject":
                                     "HHT Preview for {} Game".format(
                                         next_game.get_opponent()),
                                     "html":
                                     self.preview
                                 })
        response.raise_for_status()
Beispiel #15
0
 def __init__(self, user, food, game, _id=None):
     self.user = User.get_user_by_id(user)
     self.food = food
     self.game = Game.get_game_by_id(game)
     self._id = uuid.uuid4().hex if _id is None else _id
Beispiel #16
0
from src.common.database import Database
from src.models.games.game import Game

Database.initialize()
Game.load_game_details()
Beispiel #17
0
 def __init__(self, user, game, number, purchased_flag=None, _id=None):
     self.user = User.get_user_by_id(user)
     self.game = Game.get_game_by_id(game)
     self.number = number
     self.purchased_flag = purchased_flag
     self._id = uuid.uuid4().hex if _id is None else _id
Beispiel #18
0
 def build_first():
     players = Player.get_players()
     games = Game.get_games()
     for game in games:
         for player in players:
             Attendance(game._id, player.json()).save_to_mongo()
Beispiel #19
0
def admin_schedule():
    return render_template("games/admin_schedule.jinja2",
                           games=Game.get_games_by_year(
                               Year.get_current_year()._id))
Beispiel #20
0
 def build_for_new_game(game):
     players = Player.get_players()
     game = Game.get_game_by_id(game)
     for player in players:
         Attendance(game._id, player.json()).save_to_mongo()
Beispiel #21
0
 def __init__(self, user, game, created_on, conversation, _id=None):
     self.user = User.get_user_by_id(user)
     self.game = Game.get_game_by_id(game)
     self.created_on = created_on
     self.conversation = conversation
     self._id = uuid.uuid4().hex if _id is None else _id