def post(self, game_id): home = int(self.request.POST.get('home')) visiting = int(self.request.POST.get('visiting')) game = games.Game.get_by_id(int(game_id)) winner, loser = games.update(game, home, visiting) num_winners, num_losers = entries.set_pick_status(weeks.current(), ([winner], [loser])) if num_winners > 0 or num_losers > 0: view.clear_cache('/results/data') counts = entries.get_status_counts(weeks.current()) breakdown.save_status_counts( weeks.current(), counts.get(entries.Status.WIN, 0), counts.get(entries.Status.LOSS, 0), counts.get(entries.Status.VIOLATION, 0) )
def get(self): week = weeks.current() current_games = games.games_for_week(week) view.render(self, 'games', { 'week': week, 'games': sorted(current_games, key=lambda x: x.date), }, css=True, js=True)
def name_entry(entry_id, name, week=None): if week is None: week = weeks.current() entry = Entry.get_by_id(entry_id) entry.name = name entry.put() return _create_pick(entry, week)
def get(self): to_save = [] for p in entries.Pick.gql('WHERE week = :1', weeks.current()): if p.status != entries.Status.VIOLATION: p.status = 0 to_save.append(p) entries.db.put(to_save)
def post(self, entry_id): entry_id = int(entry_id) team = int(self.request.POST.get('team')) week = weeks.current() game = games.game_for_team(week, team) current_pick = entries.pick_for_entry(entry_id, week) current_game = games.game_for_team(week, current_pick.team) current_time = weeks.current_time() if current_time < weeks.deadline(week) and \ current_time < game.tz_deadline() and \ (current_game is None or current_time < current_game.tz_deadline()): entries.select_team(entry_id, weeks.current(), team) else: logging.warning('Attempt to set pick after deadline, user %s, team %s', self.user.name, teams.shortname(team)) self.abort(403)
def send_picks_email(user_id): alive_entries = entries.Entry.gql('WHERE alive = True AND name != NULL AND user_id = :1', user_id) if alive_entries.count() == 0: logging.info('No active entries for %s', user.name) return alive_entries = sorted([e.name for e in alive_entries]) week = weeks.current() deferred.defer(_email_picks_link, user_id, alive_entries, week, _queue='email')
def get(self): week = weeks.current() # make sure all the picks are closed if not entries.picks_closed(week): logging.error('Cannot advance week, all picks are not closed') self.abort(409) return complete_games(self, week) update_stats(week) alive_entries = entries.deactivate_dead_entries(week) weeks.increment() entries.create_picks(weeks.current(), alive_entries) self.redirect('/admin')
def post(self, week): week = int(week) if week + 1 < weeks.current() or not weeks.check_deadline(week + 1): self.abort(403) text = self.request.POST.get('text') count = int(self.request.get('count')) created_after = self.request.get('created-after') breakdown.save_comment(week, self.user, text) self.return_comments(week, count, after=created_after)
def _login(self, user, real_redirect): if not user: self.abort(403) self.login(user) if not self.user.name: self._redirect('/setup/activation', real_redirect) elif entries.unnamed_entries(self.user.key().id()) > 0: self._redirect('/setup/entries', real_redirect) elif not weeks.check_deadline(weeks.current()): self._redirect('/breakdown', real_redirect) else: self._redirect('/picks', real_redirect)
def email_new_entries(email, token, num_entries): logging.info('Emailing new user %s', email) week = weeks.current() args = { 'num_entries': num_entries, 'link': 'http://www.jgsuicidepool.com/login/' + token, 'week': week, 'deadline': weeks.deadline(week).strftime('%A, %B %d at %I:%M%p'), } plain = new_entries_template % args args['deadline'] = '<strong>%s</strong>' % args['deadline'] args['link'] = '<a href="%(link)s">Name Your Entries</a>' % args html = html_new_entries_template % args _send_mail([email], '2012 NFL Suicide Pool: Name New Entries', plain, html)
def get(self): reminder = self.request.GET.get('reminder') == 'true' week = weeks.current() users_by_id = users.users_by_id() alive_entries = entries.alive_entries() to_send = defaultdict(list) for p in entries.nopicks(week): entry = alive_entries[p.entry_id] if entry.name: to_send[p.user_id].append(entry.name) for user_id, user_entries in to_send.iteritems(): user = users_by_id[user_id] deferred.defer(mail.email_picks_link, user, user_entries, week, reminder, _queue='email') self.redirect('/admin')
def buyback_entry(entry_id): week = weeks.current() entry = Entry.get_by_id(entry_id) entry.alive = True entry.put() send_email_user_id = None if not weeks.check_deadline(week): # buying back before the new week has started buyback_pick = Pick.get_by_key_name(_pick_key(week, entry_id)) else: # attempting to buyback after the week has ended buyback_pick = Pick.get_by_key_name(_pick_key(week - 1, entry_id)) _create_pick(entry, week) send_email_user_id = entry.user_id if buyback_pick: buyback_pick.buyback = True buyback_pick.put() return send_email_user_id
def get(self): week = weeks.current() user_entries = entries.entries_for_user(self.user) user_picks = entries.picks_for_user(self.user, week) picks = [] for pick in user_picks.itervalues(): entry = user_entries[pick.entry_id] if entry.activated: picks.append((entry.name, entry.key().id(), pick)) args = { 'week': week, 'picks': sorted(picks), 'current_time': time.mktime(weeks.current_time().timetuple()), 'deadline': weeks.deadline(week), 'deadline_passed': not weeks.check_deadline(week), } logging.debug(args) view.render(self, 'picks', args, css=True, js=True)
def update_spreads(): week = weeks.current() changed_games = [] x = _load_url('http://www.sportsbook.ag/rss/live-nfl-football.rss', type='xml') for game in x.channel.item: team_names = _team_re.search(str(game.title)).group(1, 2) visiting_spread = _find_spread(team_names[0], game.description) home_spread = _find_spread(team_names[1], game.description) g = Game.gql('WHERE week = :1 AND home = :2 AND visiting = :3', week, teams.id(team_names[1]), teams.id(team_names[0])).get() if not g: continue if visiting_spread > 0: g.favorite = g.home elif home_spread > 0: g.favorite = g.visiting g.spread = abs(home_spread) changed_games.append(g) logging.info('%s vs %s, Favorite: %s, spread %f', teams.shortname(g.visiting), teams.shortname(g.home), teams.shortname(g.favorite), g.spread) db.put(changed_games)
def get(self): week = weeks.current() # re-evaluate games/stats for last week last_week = week - 1 complete_games(self, last_week) update_stats(last_week) # find any picks that need to be created based on changes picks_to_create = [] picks_for_week = entries.all_picks(week) for entry_id,e in entries.alive_entries().iteritems(): if entry_id not in picks_for_week: picks_to_create.append(e) entries.create_picks(week, picks_to_create) # send pick links for any newly created picks users_by_id = users.users_by_id() for entry in picks_to_create: user = users_by_id[entry.user_id] deferred.defer(mail.email_picks_link, user, [entry], week, False, _queue='email') self.redirect('/admin')
def get(self): week = weeks.current() current_time = weeks.current_time() if current_time > weeks.deadline(week): closed = entries.close_picks(week) if closed > 0: view.clear_cache('/results/data') counts = entries.get_team_counts(week) logging.info('Saving counts: %s', counts) breakdown.save_team_counts(week, counts) breakdown.save_status_counts(week, 0, 0, entries.num_violations(week)) self.redirect('/admin') return past_deadline = [] for g in games.open_past_deadline(week, current_time): past_deadline.append(g.home) past_deadline.append(g.visiting) closed = entries.close_picks(week, past_deadline) if closed > 0: view.clear_cache('/results/data') self.redirect('/admin')
def get(self): week = weeks.current() - 1 if not weeks.check_deadline(weeks.current()): # after the deadline users can see the stats breakdown week += 1 view.render(self, 'breakdown', {'week': week}, js=True, css=True)
def get(self): games.reset_for_week(weeks.current()) self.redirect('/')
def get(self): week = weeks.current() load_scores(week) self.redirect('/games')
def get(self): week = weeks.current() (no_pick, picks, total) = breakdown.get_team_counts(week) emails = users.get_all_emails() deferred.defer(mail.email_breakdown, week, no_pick, picks, emails, _queue='email') self.redirect('/admin')