本文整理汇总了Python中models.Game.update_game方法的典型用法代码示例。如果您正苦于以下问题:Python Game.update_game方法的具体用法?Python Game.update_game怎么用?Python Game.update_game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.update_game方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profile
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import update_game [as 别名]
def profile(request, form_id):
api = SteamAPI()
user_id = retrieve_steam_id(form_id, api)
api.user_id = user_id
try:
user = SteamUser.objects.get(steamid=user_id)
user.update_profile(api.user_call('user'))
user.update_games(api.user_call(mode='game', include_played_free_games=1))
user.update_appid_list()
user.save()
except SteamUser.DoesNotExist:
user = SteamUser()
user.update_profile(api.user_call('user'))
user.update_games(api.user_call(mode='game', include_played_free_games=1))
user.update_appid_list()
user.save()
except:
raise
return HttpResponseRedirect(reverse('gamelist:index'))
finally:
#Declare / Initialize User Statistics
user_stats = {}
user_stats['account_worth'] = float(0)
user_stats['playtimes'] = user.get_playtimes()
user_stats['total_playtime'] = user.get_total_playtime()
user_stats['unplayed_game_count'] = user.get_unplayed_game_count()
#Declare / Initialize Game List
allGames = []
newGames = []
existingGames = Game.objects.filter(steam_appid__in=user.appid_list)
newIds = set(user.appid_list) - set(game.steam_appid for game in existingGames)
#If there are new games to be added to database
if len(newIds) != 0:
#Filter out InvalidApp from newIds
invalidIds = InvalidApp.objects.filter(steam_appid__in=newIds)
newIds = newIds - set(game.steam_appid for game in invalidIds)
#Loop to add new games to DB
for newId in newIds:
try:
print "Game Does Not Exist, %s. Adding to Database." % newId
data = api.store_call(interface='appdetails', appids=newId)
newGame = Game()
newGame.update_game(newId, data)
newGame.update_igdb_data()
newGame.save()
newGames.append(newGame)
except:
pass
#Create List of Up-To-Date Games
for game in chain(existingGames, newGames):
try:
if len(game.price_overview) != 0:
user_stats['account_worth'] += game.price_overview['initial']
allGames.append(game)
except(TypeError):
pass
#sort game for table
allGames.sort(key=lambda x: x.name.lower())
#pagination
paginator = Paginator(allGames, 50)
page = request.GET.get('page')
try:
games_list = paginator.page(page)
except PageNotAnInteger:
games_list = paginator.page(1)
except EmptyPage:
games_list = paginator.page(paginator.num_pages)
return render(request, 'gamelist/profile.html', {
#User Data and List
'steam_id': api.user_id,
'user': user,
'games_list': games_list,
#User Stats
'account_worth': user_stats['account_worth']/100,
'playtimes': user_stats['playtimes'],
'total_playtime': round(user_stats['total_playtime']/60, 2),
'unplayed_games': user_stats['unplayed_game_count']
})