当前位置: 首页>>代码示例>>Python>>正文


Python Game.update_game方法代码示例

本文整理汇总了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']
		})
开发者ID:kevinfiol,项目名称:djangosteam,代码行数:91,代码来源:views.py


注:本文中的models.Game.update_game方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。