コード例 #1
0
def main(roster, teams, league_id, players):
	roster_counter = 1
	roster = open(roster).readlines()
	if len(roster) == 1:
		#this is indicative of the \r that Jordi's (probably windows) text editor uses as newlines (so check for it)
		if "\r" in roster[0]:
			roster = roster[0].split("\r")
		else:
			print roster[0]
			exit()
	output = []
	if not players:
		players = {}
	else:
		for p in players:
			output.append({p:players[p]})
			roster_counter += 1
		
	for player in roster:
		player = extract_player(player, roster_counter, teams, league_id)
		roster_counter += 1
		players[player.name] = player.get_hash()
		output.append(player.get_hash())
		

	yaml_buffer = sanitize_yaml(yaml.dump(output, default_flow_style=False))
	for y in yaml_buffer:
		print y
コード例 #2
0
def main(match_file, teams, league_id, fixture=False, existing_matches=None):
	matches = open(match_file).readlines()
	if existing_matches:
		match_list = yaml.load(open(existing_matches))
	else:
		match_list = []
	for m in matches:
		match = parse_match(m, teams, league_id)
		match_list.append(match.get_hash())
	
	if fixture:
		yaml_buffer = sanitize_yaml(yaml.dump(match_list, default_flow_style=False))
		for y in yaml_buffer:
			print y
	else:
		print yaml.dump(match_list, default_flow_style=False)
コード例 #3
0
def main(team_file, fixture, existing_teams=None, league_id = 1):
	#read in a match file and make a set of match objects out of it
	#assume for world and euro cup that the country name is the same as the team name
	team_hash = {}
	output = []
	team_counter = 1
	teams = open(team_file).readlines()
	#check to see if we've been provided a set of existing teams
	if existing_teams:
		existing_teams = yaml.load(open(existing_teams))
		for t in existing_teams:
			team_hash[team_counter] = t
			team_counter += 1
		output = existing_teams
		#get the new initial counter value
		#team_counter = get_max_team_id(existing_teams)
		
	for line in teams:
		data = line.strip().split(";")
		name = data[1]
		country = data[1]
		abbrv = data[0]
		if exists(name, team_hash):
			alt_name =  name + str(random.randint(1,1000)) #I'm making an assumption that we won't have 1000 teams with the same name
			print alt_name
			t = Team(team_counter, league_id, name, country, abbrv,altname=alt_name)
		else:
			t = Team(team_counter, league_id, name, country, abbrv)
		output.append(t.get_hash())
		team_hash[team_counter] = t.get_hash()
		team_counter += 1
	if fixture:
		yaml_buffer = sanitize_yaml(yaml.dump(output, default_flow_style=False))
		for y in yaml_buffer:
			print y
	else:
		print yaml.dump(output, default_flow_style=False)