Пример #1
0
def scrape_squad(request, team_name):
	scraper = SquadScraper()

	cricinfo_ids = scraper.scrape_entire_squad(team_name)
	for id in cricinfo_ids:
		if(len(Player.objects.filter(cricinfo_id=id)) == 0):
			profile_scraper = ProfileScraper(id)
			profile_info = profile_scraper.scrape_profile()

			new_player_object = Player.create_player(profile_info["player_info"], id)

			if(new_player_object.id != None):
				for batting_stat_row in profile_info["batting_stats"]:
				
					batting_stat_obj = BattingStat.create_batting_stat(batting_stat_row, new_player_object)

					if(batting_stat_obj.id == None):
						return HttpResponse("something went wrong parsing " + json.dumps(batting_stat_row))


	return HttpResponse(scraper.scrape_entire_squad(team_name))
Пример #2
0
def player_add(request, cric_info_id):

	# if(len(Player.objects.filter(cricinfo_id=cric_info_id)) == 0):
		#means the player's not in our database
		scraper = ProfileScraper(cric_info_id)
		profile_info = scraper.scrape_profile()

		# new_player_object = Player.create_player(profile_info["player_info"], cric_info_id)
		returnVal = ""
		
		if(new_player_object.id != None):
			for batting_stat_row in profile_info["batting_stats"]:
				
				batting_stat_obj = BattingStat.create_batting_stat(batting_stat_row, new_player_object)

				if(batting_stat_obj.id == None):
					return HttpResponse("something went wrong parsing " + json.dumps(batting_stat_row))

				

			return HttpResponse(json.dumps(profile_info))
		else:
			return HttpResponse("error scraping profile")