# Path: misc_utils.py
# def print_ignore(input):
# 	try:
# 		print input
# 	except UnicodeError:
# 		pass


import sys
import urllib3
import json
import requests
from app.models import *
from pprint import pprint
from date_utils import *
from trueskill_functions import *
from misc_utils import print_ignore

	# associate with TournamentHeader
	tournament_header = TournamentHeader.query.filter(TournamentHeader.name==sub_tournament_info.parent).first()
	tournament_header.sub_tournaments.append(new_sub_tournament)
	new_sub_tournament.region = new_sub_tournament.header.region

	db.session.commit()
	print "\n---SUBTOURNAMENT---", new_sub_tournament
	return new_sub_tournament

# Import smashgg entrants and create User objects in database
def import_tournament_entrants(entrant_list, tournament_obj):
	for entrant in entrant_list:
		player_tag = entrant.player_tag
		checked_player = check_set_user(player_tag, tournament_obj.region)

		tournament_obj.placements.append(Placement(
										tournament_id=tournament_obj.id,
										tournament_name=tournament_obj.name,
										user_id=checked_player.id,
										placement=int(entrant.player_sub_placing)
										))
	tournament_obj.entrants = len(entrant_list)
	db.session.commit()
	return tournament_obj

# Import smashgg sets, associate them with Tournament and create Set objects in database
def import_tournament_sets(set_list, sub_tournament):
	print '\n---SETS---'
	for set in set_list:

# Path: misc_utils.py
# def print_ignore(input):
# 	try:
# 		print input
# 	except UnicodeError:
# 		pass


# Path: parsers/parse_smashgg_info.py
import sys
import urllib3
import json
import requests
from app.models import *
from pprint import pprint
from date_utils import *
from trueskill_functions import *
from misc_utils import print_ignore


	# associate with TournamentHeader
	tournament_header = TournamentHeader.query.filter(TournamentHeader.name==sub_tournament_info.parent).first()
	tournament_header.sub_tournaments.append(new_sub_tournament)
	new_sub_tournament.region = new_sub_tournament.header.region

	db.session.commit()
	print "\n---SUBTOURNAMENT---", new_sub_tournament
	return new_sub_tournament

# Import smashgg entrants and create User objects in database
def import_tournament_entrants(entrant_list, tournament_obj):
	for entrant in entrant_list:
		player_tag = entrant.player_tag
		checked_player = check_set_user(player_tag, tournament_obj.region)

		tournament_obj.placements.append(Placement(
										tournament_id=tournament_obj.id,
										tournament_name=tournament_obj.name,
										user_id=checked_player.id,
										placement=int(entrant.player_sub_placing)
										))
	tournament_obj.entrants = len(entrant_list)
	db.session.commit()
	return tournament_obj

# Import smashgg sets, associate them with Tournament and create Set objects in database
def import_tournament_sets(set_list, sub_tournament):
	print '\n---SETS---'
	for set in set_list:

		print_ignore(set)