Example #1
0
    def post(self):
        counters.pingpong_incr(report_counter)
        games = self.request.get_all('a')
        games = utils.find_games_by_id(games)
        steam_id = self.request.get('id')
        games = [x for x in games if x is not None]

        self.render('report.html',games=games,steam_id=steam_id)
Example #2
0
    def get(self):
        """
        Return codes for get_user():
        1 - New user succesfully added
        2 - User update succeeded
        3 - New user was private, not added
        4 - Current user, no need for update, sucesfully returned
        5 - Update failed - private profile
        6 - Update failed - too soon since last update
        7 - Bad Steam ID

        """

        counters.pingpong_incr(main_counter)
        steam_id = self.request.get('steamid')
        mp = self.request.get('mp')
        mp = True if mp == 'y' else False
        stats = utils.retrieve_stats()

        if stats.updating: # If we're performing maintanence
            self.render('updating.html')

        else:
            if steam_id:
                user, rc = users.get_user(steam_id, stats)
                have_error = False
                error_msg = ""
                success_msg = ""
                if rc == 1:
                    # User succesfully returned
                    pass
                elif rc == 2:
                    # User update succeeded
                    success_msg = """
                    There was some recent updates to the Steam Database or <a href='http://howlongtobeat.com'>
                    HowLongToBeat.com</a>. We've updated %s's details to match the new info.
                    """  % user.username
                elif rc == 3:
                    # New user was private, not added
                    have_error = True
                    error_msg = "The profile for %s is private." % steam_id
                elif rc == 5:
                    # Update failed - private profile
                    success_msg = """
                    There have been some recent updates to the Steam Database or <a href='http://howlongtobeat.com'>
                    HowLongToBeat.com</a>. We've updated the counts for this Steam ID accordingly, but we noticed
                    it was changed to private since last we looked. If this is your Steam ID and you have bought any
                    new items recently and would like your counts to be accurate, please set your Steam Profile to public
                    temporarily, and then <a href="/update?steam_id=%s">update</a>.
                    """ % steam_id
                elif rc == 6:
                    # Update failed - too soon since last update
                    have_error = False
                    success_msg = "You can only update a Steam ID once per minute. Try again soon."
                elif rc == 7:
                    # Bad Steam ID
                    have_error = True
                    error_msg = "I couldn't find a Steam account with the URL or ID of %s. Please try to enter either your Steam Community ID, or the full URL to your profile. <p class='center'><a href='/'>Try again?</a></p>" % steam_id

                if have_error:
                    self.render('error.html', error_message=error_msg)

                else:
                    games = utils.find_games_by_id(user.games)
                    games = [x for x in games if x is not None] # Just in case an appid in their list doesn't seem to exist
                    
                    # Filter out multiplayer only games if needed
                    if mp is False:
                        games = [x for x in games if x.multiplayer_only is False]

                    # Chunk up those with HLTB stats and those without
                    with_stats = [x for x in games if x.main is not None or x.completion is not None]
                    without_stats = [x for x in games if x.main is None and x.completion is None]
    
                    with_stats = sorted(with_stats, key=lambda main: main.main, reverse=True)
                    without_stats = sorted(without_stats, key=lambda name: name.game_name)      

                    # Users games and hours are kept in parallel dictionaries in the datastore
                    hours_and_games = dict(zip(user.games, user.hours))
                    
                    # Dict with info to be sent to the Jinja2 template
                    user_hour_info = {}
                    if mp:
                        # TODO - May run into some division by zero errors here for empty profiles/those that haven't played
                        # any games
                        percent_main = "%.2f" % ((user.hours_played / user.hours_needed_main) * 100)
                        percent_complete = "%.2f" % ((user.hours_played / user.hours_needed_completion) * 100)
                        days = "%.2f" % (user.hours_needed_main/24)
                        user_hour_info = {'played': "%.2f" % (user.hours_played), 'main_needed': "%.2f" % user.hours_needed_main,\
                        'completion_needed': "%.2f" % user.hours_needed_completion, 'per_main': percent_main, 'per_complete': percent_complete,'days': days}
                    else:
                        days = "%.2f" % ((user.hours_needed_main - user.needed_main_nmp)/24)
                        percent_main = "%.2f" % ((user.hours_without_mp  / (user.hours_needed_main - user.needed_main_nmp)) * 100)
                        percent_complete = "%.2f" % ((user.hours_without_mp  / (user.hours_needed_completion - user.needed_complete_nmp)) * 100)
                        user_hour_info = {'played': "%.2f" % user.hours_without_mp, 'main_needed': "%.2f" % (user.hours_needed_main - user.needed_main_nmp), 'completion_needed':\
                        "%.2f" % (user.hours_needed_main - user.needed_complete_nmp), 'per_main':percent_main, 'per_complete': percent_complete,'days': days}

                    self.render('details.html', user=user, notice=success_msg,with_stats=with_stats,
                        without_stats=without_stats,stats=stats, hours_and_games=hours_and_games,mp=mp,user_hour_info=user_hour_info)
    
            else:
                total_hits = utils.retrieve_hit_count()
                total_queries, total_ids = utils.retrieve_counts()
                self.render('index.html', total=total_hits,queries=total_queries,ids=total_ids)