def set_name_and_team(re_match, group_name, game, sample): if group_name in re_match.groupdict() and re_match.group( group_name) is not None: player = re_match.group(group_name) sample.set_arg(group_name, f'[[{player}]]') if sample.get_arg(f'{group_name}Team') is None: try: playerObj = Player.find_by_name(player) playerId = playerObj.id historicalPlayerObj = Player.load_by_gameday( playerId, game.season, game.day) if historicalPlayerObj is not None: teamId = historicalPlayerObj.team_id teamObj = Team.load(teamId) print( f'{player}: Found historical team data: {teamObj.full_name}' ) sample.set_arg(f'{group_name}Team', f'[[{teamObj.full_name}]]') elif playerObj.team_id is not None: teamObj = Team.load(playerObj.team_id) print( f'{player}: Falling back to current team: {teamObj.full_name}' ) sample.set_arg( f'{group_name}Team', f'maybe? [[{playerObj.league_team.full_name}]]') else: print(f'Tried but failed to look up {player}') sample.set_arg(f'{group_name}Team', 'Unknown') except: print(f'Failed to look up {player}') sample.set_arg(f'{group_name}Team', 'Unknown')
def main(player_id, player_ids): site = pwb.Site() always = False error_count = 0 page_count = 0 if (player_id): player = Player.load_one(player_id) # Load player from blaseball-mike (page_count, error_count, always) = wiki_edit(player, site, always, error_count, page_count, None, None, False) elif (player_ids): ids_list = player_ids.split(',') for player_id in ids_list: player = Player.load_one(player_id) # Load player from blaseball-mike (page_count, error_count, always) = wiki_edit(player, site, always, error_count, page_count, None, None, False) else: teams = Team.load_all() for team in teams.values(): if team.nickname == 'Shoe Thieves': for batter in team.lineup: (page_count, error_count, always) = wiki_edit(batter, site, always, error_count, page_count, team.full_name, 'Batter', False) for pitcher in team.rotation: (page_count, error_count, always) = wiki_edit(pitcher, site, always, error_count, page_count, team.full_name, 'Pitcher', False) # for batter in team.bench: # (page_count, error_count, always) = wiki_edit(batter, site, always, error_count, page_count, team.full_name, 'Batter', True) # for pitcher in team.bullpen: # (page_count, error_count, always) = wiki_edit(pitcher, site, always, error_count, page_count, team.full_name, 'Pitcher', True) print(f'Updated {page_count} pages. Error count: {error_count}.')
def team_ohio_astronauts(self): """invalid ID, multi-codepoint emoji, modifications, empty player lists, invalid Tarot""" return Team({ "id": "00000000-0000-0000-0000-000000000000", "fullName": "Ohio Astronauts", "location": "Ohio", "nickname": "Astronauts", "shorthand": "OHIO", "slogan": "Always has been...", "lineup": [], "rotation": [], "bullpen": [], "bench": ["555b0a07-a3e0-41bc-b3db-ca8f520857bc"], "seasAttr": ["SHELLED"], "permAttr": ["PARTY_TIME"], "weekAttr": ["HEATING_UP"], "gameAttr": ["GRAVITY"], "mainColor": "#333", "secondaryColor": "#999", "emoji": "№Ї№От№", "shameRuns": 0, "totalShames": 69, "totalShamings": 420, "seasonShames": 0, "seasonShamings": 0, "championships": 0, "rotationSlot": 3, "teamSpirit": 0, "card": 17, "tournamentWins": 0 })
def test_load_history(self): team = Team.load_history("d9f89a8a-c563-493e-9d64-78e4f9a55d4a", count=200) assert isinstance(team, list) assert len(team) > 0 for t in team: assert isinstance(t, Team)
def test_load_all(self): teams = Team.load_all() assert isinstance(teams, dict) assert len(teams) > 0 for key, team in teams.items(): assert isinstance(key, str) assert isinstance(team, Team) assert key == team.id
def __init__(self, data, parent): super().__init__(data, parent) self.teams = {team['id']: Team(team) for team in data.get('teams', {})} self.subleagues = { sl['id']: Subleague(sl) for sl in data.get('subleagues', {}) } self.divisions = { d['id']: Division(d) for d in data.get('divisions', {}) } self.leagues = {l['id']: League(l) for l in data.get('leagues', {})}
def main(): print("Creating map of team nicknames to full team names") all_teams = Team.load_all() names = {} for t in all_teams: team = all_teams[t] short_name = team.nickname long_name = team.full_name names[short_name] = long_name with open(OUTPUT_FILE, 'w') as f: json.dump(names, f)
def main(team_name, roster): """Retrieves a given roster from the Blaseball API and parses it for writing to the team's Blasebal Wiki navigation box.""" team_name = team # Load team from blaseball-mike team_obj = Team.load_by_name(team_name) change_level = roster # Turn team.id into the correct wiki nav page nav = id_to_nav(team_obj.id) # if nav = None something something error? # Wikitextify the team.lineup list for navbox use new_roster = textify(team_obj, change_level) # Edit the wiki using nav, --roster (change_level), and textify (new_roster) wiki_edit(nav, change_level, new_roster)
def set_team_from_string(re_match, group_name, sample): if group_name in re_match.groupdict() and re_match.group( group_name) is not None: team_name = re_match.group(group_name) if team_name == 'Dalé': team_name = 'Dale' elif team_name == 'Pies': # blaseball-mike cannot tell the Pies and Spies apart team_name = 'Philly Pies' team = Team.load_by_name(team_name) if team is not None: sample.set_arg('Player1Team', f'[[{team.full_name}]]') else: print('Did not use team from string')
def test_load_history_bad_id(self): bad_team = Team.load_history("00000000-0000-0000-0000-000000000000", count=200) assert isinstance(bad_team, list) assert len(bad_team) == 0
from blaseball_mike.models import Team from blaseball_mike.models import Game teams = Team.load_all() games = [] NUM_SEASONS = 14 for i in range(1, NUM_SEASONS + 1): games.append(Game.load_by_season(i)) print(len(games))
def test_load_by_name(self): team = Team.load_by_name("Boston Flowers") assert isinstance(team, Team)
def test_load_by_name_bad_name(self): bad_name = Team.load_by_name("Ohio Astronauts") assert bad_name is None
def team_pies_chronicler(self): """chronicler historical data, S2""" return Team({ "timestamp": "2020-07-30T02:13:38.328Z", "_id": "23e4cbc1-e9cd-47fa-a35b-bfa06f726cb7", "bench": [ "20395b48-279d-44ff-b5bf-7cf2624a2d30", "d8bc482e-9309-4230-abcb-2c5a6412446d", "cd5494b4-05d0-4b2e-8578-357f0923ff4c" ], "emoji": "0x1F967", "lineup": [ "1ba715f2-caa3-44c0-9118-b045ea702a34", "26cfccf2-850e-43eb-b085-ff73ad0749b8", "13a05157-6172-4431-947b-a058217b4aa5", "80dff591-2393-448a-8d88-122bd424fa4c", "6fc3689f-bb7d-4382-98a2-cf6ddc76909d", "15ae64cd-f698-4b00-9d61-c9fffd037ae2", "083d09d4-7ed3-4100-b021-8fbe30dd43e8", "06ced607-7f96-41e7-a8cd-b501d11d1a7e", "66cebbbf-9933-4329-924a-72bd3718f321" ], "slogan": "Pie or Die.", "bullpen": [ "0672a4be-7e00-402c-b8d6-0b813f58ba96", "62111c49-1521-4ca7-8678-cd45dacf0858", "7f379b72-f4f0-4d8f-b88b-63211cf50ba6", "906a5728-5454-44a0-adfe-fd8be15b8d9b", "90cc0211-cd04-4cac-bdac-646c792773fc", "a7b0bef3-ee3c-42d4-9e6d-683cd9f5ed84", "b85161da-7f4c-42a8-b7f6-19789cf6861d", "d2a1e734-60d9-4989-b7d9-6eacda70486b" ], "fullName": "Philly Pies", "location": "Philly", "nickname": "Pies", "rotation": [ "1732e623-ffc2-40f0-87ba-fdcf97131f1f", "9786b2c9-1205-4718-b0f7-fc000ce91106", "b082ca6e-eb11-4eab-8d6a-30f8be522ec4", "60026a9d-fc9a-4f5a-94fd-2225398fa3da", "814bae61-071a-449b-981e-e7afc839d6d6" ], "mainColor": "#399d8f", "shameRuns": 0, "shorthand": "PHIL", "totalShames": 3, "seasonShames": 3, "championships": 1, "totalShamings": 0, "seasonShamings": 0, "secondaryColor": "#ffffff", "seasonAttributes": [], "permanentAttributes": [] })
def test_load_at_time(self): team = Team.load_at_time("3f8bbb15-61c0-4e3f-8e4a-907a5fb1565e", time="2020-08-01T18:00:00Z") assert isinstance(team, Team)
def test_load_bad_team(self): with pytest.raises(ValueError): bad_team = Team.load("00000000-0000-0000-0000-000000000000")
def test_load_at_time_bad_team(self): bad_team = Team.load_at_time("00000000-0000-0000-0000-000000000000", time="2020-08-01T18:00:00Z") assert bad_team is None
def test_load_one_at_time_bad_time(self): bad_time = Team.load_at_time("3f8bbb15-61c0-4e3f-8e4a-907a5fb1565e", time="1980-01-01T00:00:00Z") assert bad_time is None
def team_crabs(self): """common case""" return Team.load("8d87c468-699a-47a8-b40d-cfb73a5660ad")
def test_load(self): bad_team = Team.load("3f8bbb15-61c0-4e3f-8e4a-907a5fb1565e") assert isinstance(bad_team, Team)