diff --git a/cogs/admins.py b/cogs/admins.py index a19d81d..13aad7c 100644 --- a/cogs/admins.py +++ b/cogs/admins.py @@ -14,8 +14,8 @@ class Admins(commands.Cog): def __init__(self, bot): self.bot = bot - async def cog_command_error(self, ctx, error): - await ctx.send(f'{error}') + # async def cog_command_error(self, ctx, error): + # await ctx.send(f'{error}') @commands.command(name='current', help='Current db info') @commands.is_owner() @@ -86,94 +86,98 @@ class Admins(commands.Cog): current = await db_get('current') await ctx.send(f'Current: {current}') - @commands.command(name='sendmoves', help='Send moves to sheets') - @commands.is_owner() - async def send_moves_command(self, ctx): - current = await db_get('current') - await ctx.send('Authenticating with sheets...') - sheets = pygsheets.authorize(service_file='storage/major-domo-service-creds.json') - trans_tab = sheets.open_by_key(SBA_ROSTER_KEY).worksheet_by_title('Transactions') - await ctx.send('Collecting transactions...') - all_vals = [] - all_moves = await get_transactions( - season=current['season'], - timeout=30 - ) - await ctx.send(f'Processing transactions ({len(all_moves)} found)...') - total_moves = len(all_moves) + # @commands.command(name='sendmoves', help='Send moves to sheets') + # @commands.is_owner() + # async def send_moves_command(self, ctx): + # current = await db_get('current') + # await ctx.send('Authenticating with sheets...') + # sheets = pygsheets.authorize(service_file='storage/major-domo-service-creds.json') + # trans_tab = sheets.open_by_key(SBA_ROSTER_KEY).worksheet_by_title('Transactions') + # await ctx.send('Collecting transactions...') + # all_vals = [] + # all_moves = await get_transactions( + # season=current['season'], + # timeout=30 + # ) + # await ctx.send(f'Processing transactions ({len(all_moves)} found)...') + # total_moves = len(all_moves) + # + # counter = 0 + # for move in [*all_moves.values()]: + # all_vals.insert( + # 0, + # [ + # move['player']['name'], + # move['oldteam']['sname'], + # move['newteam']['sname'], + # move['week'], + # total_moves + 416 - counter + # ] + # ) + # counter += 1 + # logging.warning(f'all_vals samples:\n0: {all_vals[0]}\n100: {all_vals[100]}\n1000: {all_vals[1000]}\n' + # f'2000: {all_vals[2000]}') + # + # await ctx.send('Sending transactions to sheets...') + # try: + # trans_tab.update_values( + # crange=f'A420', + # values=all_vals + # ) + # await ctx.send('All done!') + # except Exception as e: + # await ctx.send('Failed sending to sheets') - counter = 0 - for move in [*all_moves.values()]: - all_vals.insert( - 0, - [ - move['player']['name'], - move['oldteam']['sname'], - move['newteam']['sname'], - move['week'], - total_moves + 416 - counter - ] - ) - counter += 1 - logging.warning(f'all_vals samples:\n0: {all_vals[0]}\n100: {all_vals[100]}\n1000: {all_vals[1000]}\n' - f'2000: {all_vals[2000]}') + # @commands.command(name='xpick', help='Expansion pick') + # @commands.is_owner() + # async def expansion_pick_command(self, ctx, team_abbrev, *, name): + # current = await db_get('current') + # player_cog = self.bot.get_cog('Players') + # player_name = await fuzzy_player_search(ctx, ctx.channel, self.bot, name, player_cog.player_list.keys()) + # player = await get_one_player(player_name) + # team = await get_one_team(team_abbrev) + # old_team = copy.deepcopy(player["team"]) + # + # if not team: + # await ctx.send(f'Who the fuck is **{team_abbrev}**? Get your shit together - it\'s DRAFT TIME!!!') + # return + # + # if old_team['id'] == 99: + # await ctx.send(f'Tell that bastard they\'re an idiot. {player["name"]} is a Free Agent.') + # return + # + # await patch_player(player['id'], team_id=team['id']) + # await ctx.send(content=None, embed=await get_player_embed(await get_one_player(player['id']), current)) + # await send_to_channel( + # self.bot, + # 's4-draft-picks', + # f'Expansion Draft: {await get_emoji(ctx, team["sname"])}{team["sname"]} select **{player["name"]}** from ' + # f'{await get_emoji(ctx, old_team["sname"])}{old_team["abbrev"]}' + # ) - await ctx.send('Sending transactions to sheets...') - try: - trans_tab.update_values( - crange=f'A420', - values=all_vals - ) - await ctx.send('All done!') - except Exception as e: - await ctx.send('Failed sending to sheets') - - @commands.command(name='xpick', help='Expansion pick') - @commands.is_owner() - async def expansion_pick_command(self, ctx, team_abbrev, *, name): - current = await db_get('current') - player_cog = self.bot.get_cog('Players') - player_name = await fuzzy_player_search(ctx, ctx.channel, self.bot, name, player_cog.player_list.keys()) - player = await get_one_player(player_name) - team = await get_one_team(team_abbrev) - old_team = copy.deepcopy(player["team"]) - - if not team: - await ctx.send(f'Who the fuck is **{team_abbrev}**? Get your shit together - it\'s DRAFT TIME!!!') - return - - if old_team['id'] == 99: - await ctx.send(f'Tell that bastard they\'re an idiot. {player["name"]} is a Free Agent.') - return - - await patch_player(player['id'], team_id=team['id']) - await ctx.send(content=None, embed=await get_player_embed(await get_one_player(player['id']), current)) - await send_to_channel( - self.bot, - 's4-draft-picks', - f'Expansion Draft: {await get_emoji(ctx, team["sname"])}{team["sname"]} select **{player["name"]}** from ' - f'{await get_emoji(ctx, old_team["sname"])}{old_team["abbrev"]}' - ) - - @commands.command(name='injimport') - @commands.is_owner() - async def injury_import_command(self, ctx): - sheets = pygsheets.authorize(service_file='storage/major-domo-service-creds.json') - inj_tab = sheets.open_by_key('1uKRf7YwTcEfp8D7gUutQRwnOHW37hl6XcBbtqw3PbN4').worksheet_by_title('Sheet1') - raw_data = inj_tab.get_values('A1', 'B545') - - for line in raw_data: - player = await get_one_player(line[0]) - await patch_player(player['id'], pitcher_injury=line[1]) + # @commands.command(name='injimport') + # @commands.is_owner() + # async def injury_import_command(self, ctx): + # sheets = pygsheets.authorize(service_file='storage/major-domo-service-creds.json') + # inj_tab = sheets.open_by_key('1uKRf7YwTcEfp8D7gUutQRwnOHW37hl6XcBbtqw3PbN4').worksheet_by_title('Sheet1') + # raw_data = inj_tab.get_values('A1', 'B545') + # + # for line in raw_data: + # player = await get_one_player(line[0]) + # await patch_player(player['id'], pitcher_injury=line[1]) @commands.command(name='setdemweek', help='Set player\'s demotion week') @commands.is_owner() async def set_dem_week_command(self, ctx, week_num, *, player_name): + current = await db_get('current') player_cog = self.bot.get_cog('Players') player_name = await fuzzy_player_search(ctx, ctx.channel, self.bot, player_name, player_cog.player_list.keys()) - player = await get_one_player(player_name) + # player = await get_one_player(player_name) + p_query = await db_get('players', params=[('season', current['season']), ('name', player_name)]) + player = p_query['players'][0] + player['demotion_week'] = week_num - await patch_player(player['id'], demotion_week=week_num) + await patch_player(player) await ctx.send(random_conf_gif()) diff --git a/cogs/dice.py b/cogs/dice.py index b307389..9b7e24e 100644 --- a/cogs/dice.py +++ b/cogs/dice.py @@ -1,7 +1,7 @@ import re from helpers import * -from db_calls import * +from db_calls import get_team_by_abbrev import discord from discord.ext import commands, tasks from discord import app_commands @@ -15,16 +15,16 @@ class Dice(commands.Cog): self.rolls = [] self.current = None - self.updates.start() + # self.updates.start() - async def cog_command_error(self, ctx, error): - await ctx.send(f'{error}') + # async def cog_command_error(self, ctx, error): + # await ctx.send(f'{error}') async def get_dice_embed(self, channel, title, message): try: team_abbrev = re.split('-', channel.name) if len(team_abbrev[0]) <= 4 and team_abbrev not in ['the', 'city']: - team = await get_one_team(team_abbrev[0], timeout=1) + team = await get_team_by_abbrev(team_abbrev[0]) else: team = None except (ValueError, AttributeError, requests.ReadTimeout) as e: @@ -45,13 +45,13 @@ class Dice(commands.Cog): return embed - @tasks.loop(minutes=5) - async def updates(self): - self.current = await db_get('current') - if len(self.rolls) > 0: - all_rolls = self.rolls - self.rolls = [] - await post_dice(all_rolls) + # @tasks.loop(minutes=5) + # async def updates(self): + # self.current = await db_get('current') + # if len(self.rolls) > 0: + # all_rolls = self.rolls + # self.rolls = [] + # await post_dice(all_rolls) @commands.command(name='ab', aliases=['atbat', 'swing', 'pa'], help='ab, atbat, or swing') async def ab_roll(self, ctx): @@ -104,16 +104,16 @@ class Dice(commands.Cog): content=None, embed=await self.get_dice_embed(ctx.channel, f'At bat roll for {ctx.author.name}', roll_message) ) - this_roll = { - 'season': self.current['season'], - 'week': self.current['week'], - 'team_id': team["id"] if team else None, - 'roller': ctx.author.id, - 'dsix': d_six_one, - 'twodsix': d_six_two + d_six_three, - 'dtwenty': d_twenty - } - self.rolls.append(this_roll) + # this_roll = { + # 'season': self.current['season'], + # 'week': self.current['week'], + # 'team_id': team["id"] if team else None, + # 'roller': ctx.author.id, + # 'dsix': d_six_one, + # 'twodsix': d_six_two + d_six_three, + # 'dtwenty': d_twenty + # } + # self.rolls.append(this_roll) @commands.command(name='1d20', aliases=['d20'], help='1d20 or d20') async def dtwenty_roll(self, ctx): @@ -130,14 +130,14 @@ class Dice(commands.Cog): content=None, embed=await self.get_dice_embed(ctx.channel, f'd20 roll for {ctx.author.name}', roll_message) ) - this_roll = { - 'season': self.current['season'], - 'week': self.current['week'], - 'team_id': team["id"] if team else None, - 'roller': ctx.author.id, - 'dtwenty': d_twenty - } - self.rolls.append(this_roll) + # this_roll = { + # 'season': self.current['season'], + # 'week': self.current['week'], + # 'team_id': team["id"] if team else None, + # 'roller': ctx.author.id, + # 'dtwenty': d_twenty + # } + # self.rolls.append(this_roll) @commands.command(name='af', aliases=['fielding'], help='Advanced fielding') async def fielding_roll(self, ctx, *args): @@ -183,16 +183,16 @@ class Dice(commands.Cog): embed=await self.get_dice_embed(ctx.channel, f'Fielding roll for {ctx.author.name}', roll_message) ) - this_roll = { - 'season': self.current['season'], - 'week': self.current['week'], - 'team_id': team["id"] if team else None, - 'roller': ctx.author.id, - 'dsix': d_six_one, - 'twodsix': d_six_two + d_six_three, - 'dtwenty': d_twenty - } - self.rolls.append(this_roll) + # this_roll = { + # 'season': self.current['season'], + # 'week': self.current['week'], + # 'team_id': team["id"] if team else None, + # 'roller': ctx.author.id, + # 'dsix': d_six_one, + # 'twodsix': d_six_two + d_six_three, + # 'dtwenty': d_twenty + # } + # self.rolls.append(this_roll) @commands.command(name='i', aliases=['injury'], help='i or injury') async def injury_roll(self, ctx): @@ -210,14 +210,14 @@ class Dice(commands.Cog): if d_twenty > 8: await ctx.send(random_salute_gif()) - this_roll = { - 'season': self.current['season'], - 'week': self.current['week'], - 'team_id': team["id"] if team else None, - 'roller': ctx.author.id, - 'dtwenty': d_twenty - } - self.rolls.append(this_roll) + # this_roll = { + # 'season': self.current['season'], + # 'week': self.current['week'], + # 'team_id': team["id"] if team else None, + # 'roller': ctx.author.id, + # 'dtwenty': d_twenty + # } + # self.rolls.append(this_roll) @app_commands.command(name='injury', description='Make an injury check; rating = left of "p", games = right') @app_commands.guilds(discord.Object(id=os.environ.get('GUILD_ID'))) @@ -418,15 +418,15 @@ class Dice(commands.Cog): content=None, embed=await self.get_dice_embed(ctx.channel, f'Jump roll for {ctx.author.name}', roll_message) ) - this_roll = { - 'season': self.current['season'], - 'week': self.current['week'], - 'team_id': team["id"] if team else None, - 'roller': ctx.author.id, - 'twodsix': d_six_two + d_six_one, - 'dtwenty': d_twenty - } - self.rolls.append(this_roll) + # this_roll = { + # 'season': self.current['season'], + # 'week': self.current['week'], + # 'team_id': team["id"] if team else None, + # 'roller': ctx.author.id, + # 'twodsix': d_six_two + d_six_one, + # 'dtwenty': d_twenty + # } + # self.rolls.append(this_roll) @commands.command(name='f', aliases=['safielding', 'saf'], help='f or safielding') async def sa_fielding_roll(self, ctx, *args): @@ -1279,76 +1279,76 @@ class Dice(commands.Cog): ) ) - this_roll = { - 'season': self.current['season'], - 'week': self.current['week'], - 'team_id': team["id"] if team else None, - 'roller': ctx.author.id, - 'threedsix': d_six_one + d_six_two + d_six_three, - 'dtwenty': d_twenty - } - self.rolls.append(this_roll) + # this_roll = { + # 'season': self.current['season'], + # 'week': self.current['week'], + # 'team_id': team["id"] if team else None, + # 'roller': ctx.author.id, + # 'threedsix': d_six_one + d_six_two + d_six_three, + # 'dtwenty': d_twenty + # } + # self.rolls.append(this_roll) - @commands.command(name='s', aliases=['shift']) - async def shift_roll(self, ctx): - """ - Make an infield shift roll. - """ - team = None - d_six_one = random.randint(1, 6) - d_twenty = random.randint(1, 20) - d_twenty_two = random.randint(1, 20) - embed = None - - if d_twenty < 3: - roll_message = f'```md\nHit into shift, consult chart```\n' \ - f'At bat roll for {ctx.author.name}\n```md\n# {d_six_one},{d_twenty_two}' \ - f'\nDetails:[1d6;1d20 ({d_six_one} - {d_twenty_two})]```' - embed = await self.get_dice_embed(ctx.channel, None, None) - embed.title = 'Hit Into Shift Results' - embed.set_image(url='https://lh3.googleusercontent.com/rouutaPsSd58B7XhGMc_uyo1CIP6I9QGRLnD0ZilizVoyaenKA' - 'GxHETVfsNisQ3rfxbIRYcRuiBxpMZVG-7lH0TvDHgipV6UW2XH7eWhDS4egEAXOyrjuOgqZVi72Uc2TItcIo' - 'hV8y5neRrck_N6juJzIsSm2YlZz5Pqyk_jRckK2qqyI5t15uBpoY9XbjmvgkJDNyaKBQYh7TgHd42BMzanYo' - 'Gr0gmCgLpiRcYxA3qEpSnxEzL7XGYODczTj6kiPOknFc6vQtcLoZ75wYqqU1AG9u5URKOckIworz0uJxrFaR' - 'PwewW5Fnxj36tf6bO37zl-RuH-veLBADtFmdEUT0pGt8eCmoB7YD6WtFG048Ox0n7U_QI3xIsvpMsnIVjml_' - 'sKQ55cHqsMZbnJLFXIO73Fl4xQFS1eqI-FjzwvK_kmslPznxfb0uz-WtBQ3fTUV--07ya-b_n4O0H38IVKKa' - 'eQqKzdTjU6Uv0uV8375UsNdSif5cbsfBp7_qlrZx4zFWc-IafCNh3h5R_NqLBV_-VQVqQdyu15Mbjr3s7kwB' - 'DANYsk9zv3grE1yoKzzAPtRILXxPpJz6MkXDPNSTDPOd6ZXR7uoyevt5BvvcWnf7Htgai8WtKHp3Zcd_bIGJ' - 'sGhohp4g3JO8zK5WMKN3-Za-KxH9XxDwrik-dc05x5VeX99m2A9eKClNbQGdE4TaI=w632-h292-no?authu' - 'ser=0') - else: - roll_message = f'```md\n' - if d_twenty < 9 and d_six_one > 3: - roll_message += f'Swing away, HR becomes 2B if beating the shift```\n' - else: - roll_message += f'Swing away, no effect```\n' - - await ctx.channel.send( - content=None, - embed=await self.get_dice_embed( - ctx.channel, - f'Shift roll for {ctx.author.name}', - roll_message - ) - ) - - this_roll = { - 'season': self.current['season'], - 'week': self.current['week'], - 'team_id': team["id"] if team else None, - 'roller': ctx.author.id, - 'dsix': d_six_one, - 'dtwenty': d_twenty - } - self.rolls.append(this_roll) - this_roll = { - 'season': self.current['season'], - 'week': self.current['week'], - 'team_id': team["id"] if team else None, - 'roller': ctx.author.id, - 'dtwenty': d_twenty_two - } - self.rolls.append(this_roll) + # @commands.command(name='s', aliases=['shift']) + # async def shift_roll(self, ctx): + # """ + # Make an infield shift roll. + # """ + # team = None + # d_six_one = random.randint(1, 6) + # d_twenty = random.randint(1, 20) + # d_twenty_two = random.randint(1, 20) + # embed = None + # + # if d_twenty < 3: + # roll_message = f'```md\nHit into shift, consult chart```\n' \ + # f'At bat roll for {ctx.author.name}\n```md\n# {d_six_one},{d_twenty_two}' \ + # f'\nDetails:[1d6;1d20 ({d_six_one} - {d_twenty_two})]```' + # embed = await self.get_dice_embed(ctx.channel, None, None) + # embed.title = 'Hit Into Shift Results' + # embed.set_image(url='https://lh3.googleusercontent.com/rouutaPsSd58B7XhGMc_uyo1CIP6I9QGRLnD0ZilizVoyaenKA' + # 'GxHETVfsNisQ3rfxbIRYcRuiBxpMZVG-7lH0TvDHgipV6UW2XH7eWhDS4egEAXOyrjuOgqZVi72Uc2TItcIo' + # 'hV8y5neRrck_N6juJzIsSm2YlZz5Pqyk_jRckK2qqyI5t15uBpoY9XbjmvgkJDNyaKBQYh7TgHd42BMzanYo' + # 'Gr0gmCgLpiRcYxA3qEpSnxEzL7XGYODczTj6kiPOknFc6vQtcLoZ75wYqqU1AG9u5URKOckIworz0uJxrFaR' + # 'PwewW5Fnxj36tf6bO37zl-RuH-veLBADtFmdEUT0pGt8eCmoB7YD6WtFG048Ox0n7U_QI3xIsvpMsnIVjml_' + # 'sKQ55cHqsMZbnJLFXIO73Fl4xQFS1eqI-FjzwvK_kmslPznxfb0uz-WtBQ3fTUV--07ya-b_n4O0H38IVKKa' + # 'eQqKzdTjU6Uv0uV8375UsNdSif5cbsfBp7_qlrZx4zFWc-IafCNh3h5R_NqLBV_-VQVqQdyu15Mbjr3s7kwB' + # 'DANYsk9zv3grE1yoKzzAPtRILXxPpJz6MkXDPNSTDPOd6ZXR7uoyevt5BvvcWnf7Htgai8WtKHp3Zcd_bIGJ' + # 'sGhohp4g3JO8zK5WMKN3-Za-KxH9XxDwrik-dc05x5VeX99m2A9eKClNbQGdE4TaI=w632-h292-no?authu' + # 'ser=0') + # else: + # roll_message = f'```md\n' + # if d_twenty < 9 and d_six_one > 3: + # roll_message += f'Swing away, HR becomes 2B if beating the shift```\n' + # else: + # roll_message += f'Swing away, no effect```\n' + # + # await ctx.channel.send( + # content=None, + # embed=await self.get_dice_embed( + # ctx.channel, + # f'Shift roll for {ctx.author.name}', + # roll_message + # ) + # ) + # + # this_roll = { + # 'season': self.current['season'], + # 'week': self.current['week'], + # 'team_id': team["id"] if team else None, + # 'roller': ctx.author.id, + # 'dsix': d_six_one, + # 'dtwenty': d_twenty + # } + # self.rolls.append(this_roll) + # this_roll = { + # 'season': self.current['season'], + # 'week': self.current['week'], + # 'team_id': team["id"] if team else None, + # 'roller': ctx.author.id, + # 'dtwenty': d_twenty_two + # } + # self.rolls.append(this_roll) @commands.command( name='lookups', help='Fielding chart lookup', diff --git a/cogs/fun.py b/cogs/fun.py index 522b7cc..060ca10 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -165,8 +165,8 @@ class Fun(commands.Cog): logging.info(f'Deleted {del_counter} commands; sent deletion notifications to {len(del_notifs)} users; ' f'sent warnings to {len(warn_notifs)} users') - async def cog_command_error(self, ctx, error): - await ctx.send(f'{error}') + # async def cog_command_error(self, ctx, error): + # await ctx.send(f'{error}') @commands.Cog.listener(name='on_message') async def on_message_listener(self, message): diff --git a/cogs/players.py b/cogs/players.py index 7f3f050..ad845e0 100644 --- a/cogs/players.py +++ b/cogs/players.py @@ -10,8 +10,7 @@ from discord.app_commands import Choice from db_calls_gameplay import get_one_game from helpers import * -from db_calls import db_get, db_patch, db_post, db_delete, get_team_by_abbrev, get_team_by_owner, patch_player, \ - get_player_by_name +from db_calls import db_get, db_patch, get_team_by_abbrev, get_team_by_owner, patch_player, get_player_by_name from typing import Literal @@ -1825,36 +1824,36 @@ class Players(commands.Cog): async def picks_command(self, ctx, *team_abbrev): await ctx.send('Go away.') return - current = await db_get('current') - - if team_abbrev: - team = await get_one_team(team_abbrev[0]) - else: - team = await get_team_by_owner(current['season'], ctx.author.id) - - if not team: - await ctx.send('I don\'t know what team you\'re looking for.') - return - - raw_picks = await get_draftpicks(season=5, owner_team=team, team_season=5) - logging.info(f'raw_picks: {raw_picks}') - try: - all_picks = dict(sorted(raw_picks.items(), key=lambda item: item[1]["overall"])) - except TypeError as e: - all_picks = dict(sorted(raw_picks.items(), key=lambda item: item[1]["round"])) - pick_string = '' - - for x in all_picks: - squiggles = '~~' if all_picks[x]['player'] else '' - selection = f'- {all_picks[x]["player"]["name"]}' if all_picks[x]["player"] else '' - overall = f'#{all_picks[x]["overall"]} - ' if all_picks[x]["overall"] else '' - pick_string += f'{squiggles}{overall}{all_picks[x]["origowner"]["abbrev"]} {all_picks[x]["round"]}' \ - f'{squiggles} {selection}\n' - - embed = get_team_embed(f'{team["lname"]}', team=team) - embed.add_field(name=f'Season {current["season"]} Draft Picks', value=pick_string) - - await ctx.send(content=None, embed=embed) + # current = await db_get('current') + # + # if team_abbrev: + # team = await get_one_team(team_abbrev[0]) + # else: + # team = await get_team_by_owner(current['season'], ctx.author.id) + # + # if not team: + # await ctx.send('I don\'t know what team you\'re looking for.') + # return + # + # raw_picks = await get_draftpicks(season=5, owner_team=team, team_season=5) + # logging.info(f'raw_picks: {raw_picks}') + # try: + # all_picks = dict(sorted(raw_picks.items(), key=lambda item: item[1]["overall"])) + # except TypeError as e: + # all_picks = dict(sorted(raw_picks.items(), key=lambda item: item[1]["round"])) + # pick_string = '' + # + # for x in all_picks: + # squiggles = '~~' if all_picks[x]['player'] else '' + # selection = f'- {all_picks[x]["player"]["name"]}' if all_picks[x]["player"] else '' + # overall = f'#{all_picks[x]["overall"]} - ' if all_picks[x]["overall"] else '' + # pick_string += f'{squiggles}{overall}{all_picks[x]["origowner"]["abbrev"]} {all_picks[x]["round"]}' \ + # f'{squiggles} {selection}\n' + # + # embed = get_team_embed(f'{team["lname"]}', team=team) + # embed.add_field(name=f'Season {current["season"]} Draft Picks', value=pick_string) + # + # await ctx.send(content=None, embed=embed) # @commands.command(name='fixscore', help='Change result') # @commands.has_any_role(SBA_PLAYERS_ROLE_NAME) diff --git a/cogs/transactions.py b/cogs/transactions.py index 07e9cb9..25c3d84 100644 --- a/cogs/transactions.py +++ b/cogs/transactions.py @@ -2,7 +2,7 @@ import re import copy from helpers import * -from db_calls import db_get, db_patch, get_team_by_owner, get_team_by_abbrev, get_player_by_name, patch_player +from db_calls import db_get, db_patch, get_team_by_owner, get_team_by_abbrev, get_player_by_name, patch_player, db_post from discord.ext import commands, tasks OFFSEASON_FLAG = True diff --git a/db_calls.py b/db_calls.py index 2d47e0b..30b9aa5 100644 --- a/db_calls.py +++ b/db_calls.py @@ -197,790 +197,6 @@ async def patch_player(this_player: dict): return await db_patch('players', object_id=this_player['id'], params=[], payload=this_player) -### -# TO BE DEPRECATED FUNCTIONS -### - -async def get_current(season=None): - if season is not None: - params = [('season', season)] - else: - params = [] - return await db_get('current', params=params) - - -async def patch_current( - week=None, freeze=None, season=None, transcount=None, bstatcount=None, pstatcount=None, bet_week=None, - trade_deadline=None, pick_trade_start=None, pick_trade_end=None, injury_count=None): - params = [] - if week is not None: - params.append(('week', week)) - if freeze is not None: - params.append(('freeze', freeze)) - if season is not None: - params.append(('season', season)) - if transcount is not None: - params.append(('transcount', transcount)) - if bstatcount is not None: - params.append(('bstatcount', bstatcount)) - if pstatcount is not None: - params.append(('pstatcount', pstatcount)) - if bet_week is not None: - params.append(('bet_week', bet_week)) - if trade_deadline is not None: - params.append(('trade_deadline', trade_deadline)) - if pick_trade_start is not None: - params.append(('pick_trade_start', pick_trade_start)) - if pick_trade_end is not None: - params.append(('pick_trade_end', pick_trade_end)) - if injury_count is not None: - params.append(('injury_count', injury_count)) - - resp = requests.patch(get_req_url('current', params=params), data=None, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_one_team(id_or_abbrev, season=None, is_pd=False, timeout=3): - if season is not None: - params = [('season', season)] - else: - params = None - - return await db_get('teams', object_id=id_or_abbrev, params=params) - - -async def get_team_roster(team, current_or_next): - resp = requests.get(f'{DB_URL}/v1/teams/{team["id"]}/roster/{current_or_next}', timeout=3) - if resp.status_code == 200: - return resp.json() - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_team_record(team, week_num): - resp = requests.get(f'{DB_URL}/v1/teams/{team["id"]}/record/{week_num}', timeout=3) - if resp.status_code == 200: - return resp.json() - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def patch_team( - team, manager=None, gmid=None, gmid2=None, mascot=None, stadium=None, thumbnail=None, color=None, - dice_color=None): - req_url = f'{DB_URL}/v1/teams/{team["id"]}' - other_params = False - if manager: - req_url += f'{param_char(other_params)}manager={manager}' - other_params = True - if gmid: - req_url += f'{param_char(other_params)}gmid={gmid}' - other_params = True - if gmid2: - req_url += f'{param_char(other_params)}gmid2={gmid2}' - other_params = True - if mascot: - req_url += f'{param_char(other_params)}mascot={mascot}' - other_params = True - if stadium: - req_url += f'{param_char(other_params)}stadium={stadium}' - other_params = True - if thumbnail: - req_url += f'{param_char(other_params)}thumbnail={thumbnail}' - other_params = True - if color: - req_url += f'{param_char(other_params)}color={color}' - other_params = True - if dice_color: - req_url += f'{param_char(other_params)}dice_color={dice_color}' - other_params = True - - resp = requests.patch(req_url, data=None, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_schedule( - season, team_abbrev1=None, team_abbrev2=None, away_abbrev=None, home_abbrev=None, week_start=None, - week_end=None): - req_url = f'{DB_URL}/v1/schedules?season={season}' - if team_abbrev1: - req_url += f'&team_abbrev1={team_abbrev1}' - if team_abbrev2: - req_url += f'&team_abbrev2={team_abbrev2}' - if away_abbrev: - req_url += f'&away_abbrev={away_abbrev}' - if home_abbrev: - req_url += f'&home_abbrev={home_abbrev}' - if week_start: - req_url += f'&week_start={week_start}' - if week_end: - req_url += f'&week_end={week_end}' - - return await db_get(req_url) - - -async def get_one_schedule( - season, team_abbrev1=None, team_abbrev2=None, away_abbrev=None, home_abbrev=None, week=None): - req_url = f'{DB_URL}/v1/schedules?season={season}' - if team_abbrev1: - req_url += f'&team_abbrev1={team_abbrev1}' - if team_abbrev2: - req_url += f'&team_abbrev2={team_abbrev2}' - if away_abbrev: - req_url += f'&away_abbrev={away_abbrev}' - if home_abbrev: - req_url += f'&home_abbrev={home_abbrev}' - if week: - req_url += f'&week_start={week}' - req_url += f'&week_end={week}' - - resp = await db_get(req_url) - if len(resp) > 2: - raise ValueError(f'One schedule requested, but {len(resp)} were returned') - elif len(resp) == 0: - raise ValueError(f'No schedules found') - else: - key = [*resp] - return_val = resp[key[0]] - return return_val - - -async def get_players(season, team_abbrev=None, sort=None, injured=None): - req_url = f'{DB_URL}/v2/players?season={season}' - if team_abbrev: - req_url += f'&team_abbrev={team_abbrev}' - if sort: - req_url += f'&sort={sort}' - if injured: - req_url += f'&injured={injured}' - - return await db_get(req_url) - - -async def get_one_player(id_or_name, season=None): - req_url = f'{DB_URL}/v1/players/{id_or_name}' - if season is not None: - req_url += f'?season={season}' - - return await db_get(req_url) - - -# async def patch_player( -# pid, name=None, wara=None, image=None, image2=None, team_id=None, season=None, pitcher_injury=None, pos_1=None, -# pos_2=None, pos_3=None, pos_4=None, pos_5=None, pos_6=None, pos_7=None, pos_8=None, last_game=None, -# last_game2=None, il_return=None, demotion_week=None, headshot=None, vanity_card=None, injury_rating=None): -# """ -# For values being patched to "None", set to False -# -# :param pid: -# :param name: -# :param wara: -# :param image: -# :param image2: -# :param team_id: -# :param season: -# :param pitcher_injury: -# :param pos_1: -# :param pos_2: -# :param pos_3: -# :param pos_4: -# :param pos_5: -# :param pos_6: -# :param pos_7: -# :param pos_8: -# :param last_game: -# :param last_game2: -# :param il_return: -# :return: -# """ -# req_url = f'{DB_URL}/v2/players/{pid}' -# other_params = False -# if name is not None: -# req_url += f'{param_char(other_params)}name={name}' -# other_params = True -# if wara is not None: -# req_url += f'{param_char(other_params)}wara={wara}' -# other_params = True -# if image is not None: -# req_url += f'{param_char(other_params)}image={image}' -# other_params = True -# if image2 is not None: -# if not image2: -# req_url += f'{param_char(other_params)}image2=False' -# else: -# req_url += f'{param_char(other_params)}image2={image2}' -# other_params = True -# if team_id is not None: -# req_url += f'{param_char(other_params)}team_id={team_id}' -# other_params = True -# if season is not None: -# req_url += f'{param_char(other_params)}season={season}' -# other_params = True -# if pitcher_injury is not None: -# if not pitcher_injury: -# req_url += f'{param_char(other_params)}pitcher_injury=False' -# else: -# req_url += f'{param_char(other_params)}pitcher_injury={pitcher_injury}' -# other_params = True -# if pos_1 is not None: -# req_url += f'{param_char(other_params)}pos_1={pos_1}' -# other_params = True -# if pos_2 is not None: -# if not pos_2: -# req_url += f'{param_char(other_params)}pos_2=False' -# else: -# req_url += f'{param_char(other_params)}pos_2={pos_2}' -# other_params = True -# if pos_3 is not None: -# if not pos_3: -# req_url += f'{param_char(other_params)}pos_3=False' -# else: -# req_url += f'{param_char(other_params)}pos_3={pos_3}' -# other_params = True -# if pos_4 is not None: -# if not pos_4: -# req_url += f'{param_char(other_params)}pos_4=False' -# else: -# req_url += f'{param_char(other_params)}pos_4={pos_4}' -# other_params = True -# if pos_5 is not None: -# if not pos_5: -# req_url += f'{param_char(other_params)}pos_5=False' -# else: -# req_url += f'{param_char(other_params)}pos_5={pos_5}' -# other_params = True -# if pos_6 is not None: -# if not pos_6: -# req_url += f'{param_char(other_params)}pos_6=False' -# else: -# req_url += f'{param_char(other_params)}pos_6={pos_6}' -# other_params = True -# if pos_7 is not None: -# if not pos_7: -# req_url += f'{param_char(other_params)}pos_7=False' -# else: -# req_url += f'{param_char(other_params)}pos_7={pos_7}' -# other_params = True -# if pos_8 is not None: -# if not pos_8: -# req_url += f'{param_char(other_params)}pos_8=False' -# else: -# req_url += f'{param_char(other_params)}pos_8={pos_8}' -# other_params = True -# if last_game is not None: -# if not last_game: -# req_url += f'{param_char(other_params)}last_game=False' -# else: -# req_url += f'{param_char(other_params)}last_game={last_game}' -# other_params = True -# if last_game2 is not None: -# req_url += f'{param_char(other_params)}last_game2={last_game2}' -# other_params = True -# if il_return is not None: -# if not il_return: -# req_url += f'{param_char(other_params)}il_return=false' -# else: -# req_url += f'{param_char(other_params)}il_return={il_return}' -# other_params = True -# if demotion_week is not None: -# req_url += f'{param_char(other_params)}demotion_week={demotion_week}' -# other_params = True -# if headshot is not None: -# if not headshot: -# req_url += f'{param_char(other_params)}headshot=false' -# else: -# req_url += f'{param_char(other_params)}headshot={headshot}' -# other_params = True -# if vanity_card is not None: -# if not vanity_card: -# req_url += f'{param_char(other_params)}vanity_card=false' -# else: -# req_url += f'{param_char(other_params)}vanity_card={vanity_card}' -# other_params = True -# if injury_rating is not None: -# req_url += f'{param_char(other_params)}injury_rating={injury_rating}' -# other_params = True -# -# resp = requests.patch(req_url, headers=AUTH_TOKEN, timeout=3) -# if resp.status_code == 200: -# return True -# else: -# logging.warning(resp.text) -# raise ValueError(f'DB: {resp.text}') - - -async def get_standings(season=None, team_abbrev=None, league_abbrev=None, division_abbrev=None): - req_url = f'{DB_URL}/v1/standings' - other_params = False - if season: - req_url += f'{param_char(other_params)}season={season}' - other_params = True - if team_abbrev: - req_url += f'{param_char(other_params)}team_abbrev={team_abbrev}' - other_params = True - if league_abbrev: - req_url += f'{param_char(other_params)}league_abbrev={league_abbrev}' - other_params = True - if division_abbrev: - req_url += f'{param_char(other_params)}division_abbrev={division_abbrev}' - other_params = True - - return await db_get(req_url) - - -async def get_results(season, team_abbrev=None, week=None, away_abbrev=None, home_abbrev=None): - req_url = f'{DB_URL}/v1/results?season={season}' - if team_abbrev: - req_url += f'&team_abbrev={team_abbrev}' - if week: - req_url += f'&week={week}' - if away_abbrev: - req_url += f'&away_abbrev={away_abbrev}' - if home_abbrev: - req_url += f'&home_abbrev={home_abbrev}' - - return await db_get(req_url) - - -async def get_transactions( - season, team_abbrev=None, week_start=None, week_end=None, cancelled=None, frozen=None, - player_name=None, player_id=None, move_id=None, timeout=3): - req_url = f'{DB_URL}/v1/transactions?season={season}' - if team_abbrev: - req_url += f'&team_abbrev={team_abbrev}' - if week_start: - req_url += f'&week_start={week_start}' - if week_end: - req_url += f'&week_end={week_end}' - if cancelled: - req_url += f'&cancelled={cancelled}' - if frozen: - req_url += f'&frozen={frozen}' - if player_name: - req_url += f'&player_name={player_name}' - if player_id: - req_url += f'&player_id={player_id}' - if move_id: - req_url += f'&move_id={move_id}' - - return await db_get(req_url) - - -async def post_transactions(moves: list): - req_url = f'{DB_URL}/v1/transactions' - data = { - 'count': len(moves), - 'moves': moves - } - payload = json.dumps(data) - - resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def patch_transaction(move_id, frozen=None, cancelled=None): - req_url = f'{DB_URL}/v1/transactions/{move_id}' - other_params = False - if frozen is not None: - req_url += f'{param_char(other_params)}frozen={frozen}' - other_params = True - if cancelled is not None: - req_url += f'{param_char(other_params)}cancelled={cancelled}' - other_params = True - - resp = requests.patch(req_url, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_one_battingseason(player_id): - req_url = f'{DB_URL}/v1/battingseasons/{player_id}' - - return await db_get(req_url) - - -async def get_one_pitchingseason(player_id): - req_url = f'{DB_URL}/v1/pitchingseasons/{player_id}' - - return await db_get(req_url) - - -async def get_one_fieldingseason(player_id): - req_url = f'{DB_URL}/v1/fieldingseasons/{player_id}' - - return await db_get(req_url) - - -async def get_battingcareer(name_or_id): - req_url = f'{DB_URL}/v1/battingcareer/{name_or_id}' - - return await db_get(req_url) - - -async def get_pitchingcareer(name_or_id): - req_url = f'{DB_URL}/v1/pitchingcareer/{name_or_id}' - - return await db_get(req_url) - - -async def get_battingstat( - season, s_type='regular', team_abbrev=None, player_name=None, player_id=None, week_start=None, - week_end=None, game_num=None, position=None, timeout=10): - req_url = f'{DB_URL}/v1/battingstats/s{season}/{s_type}' - other_params = False - if team_abbrev: - req_url += f'{param_char(other_params)}team_abbrev={team_abbrev}' - other_params = True - if player_name: - req_url += f'{param_char(other_params)}player_name={player_name}' - other_params = True - if player_id: - req_url += f'{param_char(other_params)}player_id={player_id}' - other_params = True - if week_start: - req_url += f'{param_char(other_params)}week_start={week_start}' - other_params = True - if week_end: - req_url += f'{param_char(other_params)}week_end={week_end}' - other_params = True - if game_num: - req_url += f'{param_char(other_params)}game_num={game_num}' - other_params = True - if position: - req_url += f'{param_char(other_params)}position={position}' - other_params = True - - return await db_get(req_url, timeout=timeout) - - -async def post_battingstats(stats: list): - req_url = f'{DB_URL}/v1/battingstats' - data = { - 'count': len(stats), - 'stats': stats - } - payload = json.dumps(data) - - resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def delete_battingstats(game_obj: dict): - req_url = f'{DB_URL}/v1/battingstats' - payload = json.dumps(game_obj) - - resp = requests.delete(req_url, data=payload, headers=AUTH_TOKEN) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def recalc_batting_seasons(season, team_id): - req_url = f'{DB_URL}/v1/battingseasons/recalculate?season={season}&team_id={team_id}' - - resp = requests.post(req_url, headers=AUTH_TOKEN, timeout=45) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def recalc_fielding_seasons(season, team_id): - req_url = f'{DB_URL}/v1/fieldingseasons/recalculate?season={season}&team_id={team_id}' - - resp = requests.post(req_url, headers=AUTH_TOKEN, timeout=45) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_pitchingstat( - season, s_type='regular', team_abbrev=None, player_name=None, player_id=None, week_start=None, - week_end=None, game_num=None, timeout=10): - req_url = f'{DB_URL}/v1/pitchingstats/s{season}/{s_type}' - other_params = False - if team_abbrev: - req_url += f'{param_char(other_params)}team_abbrev={team_abbrev}' - other_params = True - if player_name: - req_url += f'{param_char(other_params)}player_name={player_name}' - other_params = True - if player_id: - req_url += f'{param_char(other_params)}player_id={player_id}' - other_params = True - if week_start: - req_url += f'{param_char(other_params)}week_start={week_start}' - other_params = True - if game_num: - req_url += f'{param_char(other_params)}game_num={game_num}' - other_params = True - if week_end: - req_url += f'{param_char(other_params)}week_end={week_end}' - other_params = True - - return await db_get(req_url, timeout=timeout) - - -async def post_pitchingstats(stats: list): - req_url = f'{DB_URL}/v1/pitchingstats' - data = { - 'count': len(stats), - 'stats': stats - } - payload = json.dumps(data) - - resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def delete_pitchingstats(game_obj: dict): - req_url = f'{DB_URL}/v1/pitchingstats' - payload = json.dumps(game_obj) - - resp = requests.delete(req_url, data=payload, headers=AUTH_TOKEN) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def recalc_pitching_seasons(season, team_id): - req_url = f'{DB_URL}/v1/pitchingseasons/recalculate?season={season}&team_id={team_id}' - - resp = requests.post(req_url, headers=AUTH_TOKEN, timeout=45) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_draftdata(): - return await db_get('draftdata') - - -async def patch_draftdata( - currentpick=None, timer=None, pick_deadline=None, result_channel=None, ping_channel=None, pick_minutes=None): - req_url = f'{DB_URL}/v1/draftdata' - other_params = False - if currentpick is not None: - req_url += f'{param_char(other_params)}currentpick={currentpick}' - other_params = True - if timer is not None: - req_url += f'{param_char(other_params)}timer={timer}' - other_params = True - if pick_deadline is not None: - req_url += f'{param_char(other_params)}pick_deadline={pick_deadline}' - other_params = True - if result_channel is not None: - req_url += f'{param_char(other_params)}result_channel={result_channel}' - other_params = True - if ping_channel is not None: - req_url += f'{param_char(other_params)}ping_channel={ping_channel}' - other_params = True - if pick_minutes is not None: - req_url += f'{param_char(other_params)}pick_minutes={pick_minutes}' - other_params = True - - resp = requests.patch(req_url, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_draftpicks( - season, owner_team=None, orig_owner_team=None, round_start=None, round_end=None, team_season=None, - overall_start=None, overall_end=None): - req_url = f'{DB_URL}/v1/draftpicks?season={season}' - if owner_team: - req_url += f'&owner_team_abbrev={owner_team["abbrev"]}' - if orig_owner_team: - req_url += f'&orig_team_abbrev={orig_owner_team["abbrev"]}' - if round_start: - req_url += f'&pick_round_start={round_start}' - if round_end: - req_url += f'&pick_round_end={round_end}' - if team_season: - req_url += f'&team_season={team_season}' - if overall_start: - req_url += f'&overall_start={overall_start}' - if overall_end: - req_url += f'&overall_end={overall_end}' - - return await db_get(req_url) - - -async def get_one_draftpick_search(season, orig_owner_abbrev, round_num: int, team_season: int = None): - req_url = f'{DB_URL}/v1/draftpicks?season={season}' - req_url += f'&orig_team_abbrev={orig_owner_abbrev}' - req_url += f'&pick_round_start={round_num}' - req_url += f'&pick_round_end={round_num}' - if team_season is not None: - req_url += f'&team_season={team_season}' - - picks = await db_get(req_url) - if len(picks) == 0: - return None - elif len(picks) == 1: - for x in picks: - return picks[x] - - -async def get_one_draftpick_byid(pick_id: int): - req_url = f'{DB_URL}/v1/draftpicks/{pick_id}' - - return await db_get(req_url) - - -async def get_one_draftpick_byoverall(season: int, overall: int): - req_url = f'{DB_URL}/v1/draftpicks?season={season}&overall={overall}' - - resp = await db_get(req_url) - if len(resp) != 1: - return None - else: - key = [*resp] - return resp[key[0]] - - -async def patch_draftpick( - pick_id: int, overall: int = None, round: int = None, orig_owner_id: int = None, owner_id: int = None, - season: int = None, player_id: int = None): - req_url = f'{DB_URL}/v1/draftpicks/{pick_id}' - other_params = False - if overall is not None: - req_url += f'{param_char(other_params)}overall={overall}' - other_params = True - if round is not None: - req_url += f'{param_char(other_params)}round={round}' - other_params = True - if orig_owner_id is not None: - req_url += f'{param_char(other_params)}orig_owner_id={orig_owner_id}' - other_params = True - if owner_id is not None: - req_url += f'{param_char(other_params)}owner_id={owner_id}' - other_params = True - if season is not None: - req_url += f'{param_char(other_params)}season={season}' - other_params = True - if player_id is not None: - req_url += f'{param_char(other_params)}player_id={player_id}' - other_params = True - - resp = requests.patch(req_url, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_awards(player_id=None, player_name=None, season=None): - req_url = f'{DB_URL}/v1/awards' - other_params = False - if player_id: - req_url += f'{param_char(other_params)}player_id={player_id}' - other_params = True - if player_name: - req_url += f'{param_char(other_params)}player_name={player_name}' - other_params = True - if season: - req_url += f'{param_char(other_params)}season={season}' - other_params = True - - resp = requests.get(req_url, timeout=3) - if resp.status_code == 200: - return resp.json() - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def post_award(award: dict): - req_url = f'{DB_URL}/v1/awards' - award_model = { - 'name': award['name'], - 'season': award['season'], - 'timing': award['timing'], - } - if award['manager1']: - award_model['manager1_id'] = award['manager1']['id'] - if award['manager2']: - award_model['manager2_id'] = award['manager2']['id'] - if award['player']: - award_model['player_id'] = award['player']['id'] - if award['team']: - award_model['team_id'] = award['team']['id'] - if award['image']: - award_model['image'] = award['image'] - - payload_prep = {'count': 1, 'awards': [award_model]} - payload = json.dumps(payload_prep) - - resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_one_manager(manager_name): - req_url = f'{DB_URL}/v1/managers/{manager_name}' - - return await db_get(req_url) - - -async def post_dice(dice_bag: list): - req_url = f'{DB_URL}/v1/dice' - dice_model = { - 'count': len(dice_bag), - 'rolls': dice_bag - } - - payload = json.dumps(dice_model) - - resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - async def get_player_photo(player_name): req_url = f'https://www.thesportsdb.com/api/v1/json/1/searchplayers.php?p={player_name}' @@ -1008,24 +224,835 @@ async def get_player_headshot(player_name): return await get_player_photo(player_name) -async def post_draft_list(this_list: list): - req_url = f'{DB_URL}/v1/draft-list' - list_model = { - 'count': len(this_list), - 'draft_list': this_list - } +### +# TO BE DEPRECATED FUNCTIONS +### - payload = json.dumps(list_model) - - resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) - if resp.status_code == 200: - return True - else: - logging.warning(resp.text) - raise ValueError(f'DB: {resp.text}') - - -async def get_draft_list(team): - req_url = f'{DB_URL}/v1/draft-list/{team["id"]}' - - return await db_get(req_url) +# async def get_current(season=None): +# if season is not None: +# params = [('season', season)] +# else: +# params = [] +# return await db_get('current', params=params) +# +# +# async def patch_current( +# week=None, freeze=None, season=None, transcount=None, bstatcount=None, pstatcount=None, bet_week=None, +# trade_deadline=None, pick_trade_start=None, pick_trade_end=None, injury_count=None): +# params = [] +# if week is not None: +# params.append(('week', week)) +# if freeze is not None: +# params.append(('freeze', freeze)) +# if season is not None: +# params.append(('season', season)) +# if transcount is not None: +# params.append(('transcount', transcount)) +# if bstatcount is not None: +# params.append(('bstatcount', bstatcount)) +# if pstatcount is not None: +# params.append(('pstatcount', pstatcount)) +# if bet_week is not None: +# params.append(('bet_week', bet_week)) +# if trade_deadline is not None: +# params.append(('trade_deadline', trade_deadline)) +# if pick_trade_start is not None: +# params.append(('pick_trade_start', pick_trade_start)) +# if pick_trade_end is not None: +# params.append(('pick_trade_end', pick_trade_end)) +# if injury_count is not None: +# params.append(('injury_count', injury_count)) +# +# resp = requests.patch(get_req_url('current', params=params), data=None, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_one_team(id_or_abbrev, season=None, is_pd=False, timeout=3): +# if season is not None: +# params = [('season', season)] +# else: +# params = None +# +# return await db_get('teams', object_id=id_or_abbrev, params=params) +# +# +# async def get_team_roster(team, current_or_next): +# resp = requests.get(f'{DB_URL}/v1/teams/{team["id"]}/roster/{current_or_next}', timeout=3) +# if resp.status_code == 200: +# return resp.json() +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_team_record(team, week_num): +# resp = requests.get(f'{DB_URL}/v1/teams/{team["id"]}/record/{week_num}', timeout=3) +# if resp.status_code == 200: +# return resp.json() +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def patch_team( +# team, manager=None, gmid=None, gmid2=None, mascot=None, stadium=None, thumbnail=None, color=None, +# dice_color=None): +# req_url = f'{DB_URL}/v1/teams/{team["id"]}' +# other_params = False +# if manager: +# req_url += f'{param_char(other_params)}manager={manager}' +# other_params = True +# if gmid: +# req_url += f'{param_char(other_params)}gmid={gmid}' +# other_params = True +# if gmid2: +# req_url += f'{param_char(other_params)}gmid2={gmid2}' +# other_params = True +# if mascot: +# req_url += f'{param_char(other_params)}mascot={mascot}' +# other_params = True +# if stadium: +# req_url += f'{param_char(other_params)}stadium={stadium}' +# other_params = True +# if thumbnail: +# req_url += f'{param_char(other_params)}thumbnail={thumbnail}' +# other_params = True +# if color: +# req_url += f'{param_char(other_params)}color={color}' +# other_params = True +# if dice_color: +# req_url += f'{param_char(other_params)}dice_color={dice_color}' +# other_params = True +# +# resp = requests.patch(req_url, data=None, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_schedule( +# season, team_abbrev1=None, team_abbrev2=None, away_abbrev=None, home_abbrev=None, week_start=None, +# week_end=None): +# req_url = f'{DB_URL}/v1/schedules?season={season}' +# if team_abbrev1: +# req_url += f'&team_abbrev1={team_abbrev1}' +# if team_abbrev2: +# req_url += f'&team_abbrev2={team_abbrev2}' +# if away_abbrev: +# req_url += f'&away_abbrev={away_abbrev}' +# if home_abbrev: +# req_url += f'&home_abbrev={home_abbrev}' +# if week_start: +# req_url += f'&week_start={week_start}' +# if week_end: +# req_url += f'&week_end={week_end}' +# +# return await db_get(req_url) +# +# +# async def get_one_schedule( +# season, team_abbrev1=None, team_abbrev2=None, away_abbrev=None, home_abbrev=None, week=None): +# req_url = f'{DB_URL}/v1/schedules?season={season}' +# if team_abbrev1: +# req_url += f'&team_abbrev1={team_abbrev1}' +# if team_abbrev2: +# req_url += f'&team_abbrev2={team_abbrev2}' +# if away_abbrev: +# req_url += f'&away_abbrev={away_abbrev}' +# if home_abbrev: +# req_url += f'&home_abbrev={home_abbrev}' +# if week: +# req_url += f'&week_start={week}' +# req_url += f'&week_end={week}' +# +# resp = await db_get(req_url) +# if len(resp) > 2: +# raise ValueError(f'One schedule requested, but {len(resp)} were returned') +# elif len(resp) == 0: +# raise ValueError(f'No schedules found') +# else: +# key = [*resp] +# return_val = resp[key[0]] +# return return_val +# +# +# async def get_players(season, team_abbrev=None, sort=None, injured=None): +# req_url = f'{DB_URL}/v2/players?season={season}' +# if team_abbrev: +# req_url += f'&team_abbrev={team_abbrev}' +# if sort: +# req_url += f'&sort={sort}' +# if injured: +# req_url += f'&injured={injured}' +# +# return await db_get(req_url) +# +# +# async def get_one_player(id_or_name, season=None): +# req_url = f'{DB_URL}/v1/players/{id_or_name}' +# if season is not None: +# req_url += f'?season={season}' +# +# return await db_get(req_url) +# +# +# # async def patch_player( +# # pid, name=None, wara=None, image=None, image2=None, team_id=None, season=None, pitcher_injury=None, pos_1=None, +# # pos_2=None, pos_3=None, pos_4=None, pos_5=None, pos_6=None, pos_7=None, pos_8=None, last_game=None, +# # last_game2=None, il_return=None, demotion_week=None, headshot=None, vanity_card=None, injury_rating=None): +# # """ +# # For values being patched to "None", set to False +# # +# # :param pid: +# # :param name: +# # :param wara: +# # :param image: +# # :param image2: +# # :param team_id: +# # :param season: +# # :param pitcher_injury: +# # :param pos_1: +# # :param pos_2: +# # :param pos_3: +# # :param pos_4: +# # :param pos_5: +# # :param pos_6: +# # :param pos_7: +# # :param pos_8: +# # :param last_game: +# # :param last_game2: +# # :param il_return: +# # :return: +# # """ +# # req_url = f'{DB_URL}/v2/players/{pid}' +# # other_params = False +# # if name is not None: +# # req_url += f'{param_char(other_params)}name={name}' +# # other_params = True +# # if wara is not None: +# # req_url += f'{param_char(other_params)}wara={wara}' +# # other_params = True +# # if image is not None: +# # req_url += f'{param_char(other_params)}image={image}' +# # other_params = True +# # if image2 is not None: +# # if not image2: +# # req_url += f'{param_char(other_params)}image2=False' +# # else: +# # req_url += f'{param_char(other_params)}image2={image2}' +# # other_params = True +# # if team_id is not None: +# # req_url += f'{param_char(other_params)}team_id={team_id}' +# # other_params = True +# # if season is not None: +# # req_url += f'{param_char(other_params)}season={season}' +# # other_params = True +# # if pitcher_injury is not None: +# # if not pitcher_injury: +# # req_url += f'{param_char(other_params)}pitcher_injury=False' +# # else: +# # req_url += f'{param_char(other_params)}pitcher_injury={pitcher_injury}' +# # other_params = True +# # if pos_1 is not None: +# # req_url += f'{param_char(other_params)}pos_1={pos_1}' +# # other_params = True +# # if pos_2 is not None: +# # if not pos_2: +# # req_url += f'{param_char(other_params)}pos_2=False' +# # else: +# # req_url += f'{param_char(other_params)}pos_2={pos_2}' +# # other_params = True +# # if pos_3 is not None: +# # if not pos_3: +# # req_url += f'{param_char(other_params)}pos_3=False' +# # else: +# # req_url += f'{param_char(other_params)}pos_3={pos_3}' +# # other_params = True +# # if pos_4 is not None: +# # if not pos_4: +# # req_url += f'{param_char(other_params)}pos_4=False' +# # else: +# # req_url += f'{param_char(other_params)}pos_4={pos_4}' +# # other_params = True +# # if pos_5 is not None: +# # if not pos_5: +# # req_url += f'{param_char(other_params)}pos_5=False' +# # else: +# # req_url += f'{param_char(other_params)}pos_5={pos_5}' +# # other_params = True +# # if pos_6 is not None: +# # if not pos_6: +# # req_url += f'{param_char(other_params)}pos_6=False' +# # else: +# # req_url += f'{param_char(other_params)}pos_6={pos_6}' +# # other_params = True +# # if pos_7 is not None: +# # if not pos_7: +# # req_url += f'{param_char(other_params)}pos_7=False' +# # else: +# # req_url += f'{param_char(other_params)}pos_7={pos_7}' +# # other_params = True +# # if pos_8 is not None: +# # if not pos_8: +# # req_url += f'{param_char(other_params)}pos_8=False' +# # else: +# # req_url += f'{param_char(other_params)}pos_8={pos_8}' +# # other_params = True +# # if last_game is not None: +# # if not last_game: +# # req_url += f'{param_char(other_params)}last_game=False' +# # else: +# # req_url += f'{param_char(other_params)}last_game={last_game}' +# # other_params = True +# # if last_game2 is not None: +# # req_url += f'{param_char(other_params)}last_game2={last_game2}' +# # other_params = True +# # if il_return is not None: +# # if not il_return: +# # req_url += f'{param_char(other_params)}il_return=false' +# # else: +# # req_url += f'{param_char(other_params)}il_return={il_return}' +# # other_params = True +# # if demotion_week is not None: +# # req_url += f'{param_char(other_params)}demotion_week={demotion_week}' +# # other_params = True +# # if headshot is not None: +# # if not headshot: +# # req_url += f'{param_char(other_params)}headshot=false' +# # else: +# # req_url += f'{param_char(other_params)}headshot={headshot}' +# # other_params = True +# # if vanity_card is not None: +# # if not vanity_card: +# # req_url += f'{param_char(other_params)}vanity_card=false' +# # else: +# # req_url += f'{param_char(other_params)}vanity_card={vanity_card}' +# # other_params = True +# # if injury_rating is not None: +# # req_url += f'{param_char(other_params)}injury_rating={injury_rating}' +# # other_params = True +# # +# # resp = requests.patch(req_url, headers=AUTH_TOKEN, timeout=3) +# # if resp.status_code == 200: +# # return True +# # else: +# # logging.warning(resp.text) +# # raise ValueError(f'DB: {resp.text}') +# +# +# async def get_standings(season=None, team_abbrev=None, league_abbrev=None, division_abbrev=None): +# req_url = f'{DB_URL}/v1/standings' +# other_params = False +# if season: +# req_url += f'{param_char(other_params)}season={season}' +# other_params = True +# if team_abbrev: +# req_url += f'{param_char(other_params)}team_abbrev={team_abbrev}' +# other_params = True +# if league_abbrev: +# req_url += f'{param_char(other_params)}league_abbrev={league_abbrev}' +# other_params = True +# if division_abbrev: +# req_url += f'{param_char(other_params)}division_abbrev={division_abbrev}' +# other_params = True +# +# return await db_get(req_url) +# +# +# async def get_results(season, team_abbrev=None, week=None, away_abbrev=None, home_abbrev=None): +# req_url = f'{DB_URL}/v1/results?season={season}' +# if team_abbrev: +# req_url += f'&team_abbrev={team_abbrev}' +# if week: +# req_url += f'&week={week}' +# if away_abbrev: +# req_url += f'&away_abbrev={away_abbrev}' +# if home_abbrev: +# req_url += f'&home_abbrev={home_abbrev}' +# +# return await db_get(req_url) +# +# +# async def get_transactions( +# season, team_abbrev=None, week_start=None, week_end=None, cancelled=None, frozen=None, +# player_name=None, player_id=None, move_id=None, timeout=3): +# req_url = f'{DB_URL}/v1/transactions?season={season}' +# if team_abbrev: +# req_url += f'&team_abbrev={team_abbrev}' +# if week_start: +# req_url += f'&week_start={week_start}' +# if week_end: +# req_url += f'&week_end={week_end}' +# if cancelled: +# req_url += f'&cancelled={cancelled}' +# if frozen: +# req_url += f'&frozen={frozen}' +# if player_name: +# req_url += f'&player_name={player_name}' +# if player_id: +# req_url += f'&player_id={player_id}' +# if move_id: +# req_url += f'&move_id={move_id}' +# +# return await db_get(req_url) +# +# +# async def post_transactions(moves: list): +# req_url = f'{DB_URL}/v1/transactions' +# data = { +# 'count': len(moves), +# 'moves': moves +# } +# payload = json.dumps(data) +# +# resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def patch_transaction(move_id, frozen=None, cancelled=None): +# req_url = f'{DB_URL}/v1/transactions/{move_id}' +# other_params = False +# if frozen is not None: +# req_url += f'{param_char(other_params)}frozen={frozen}' +# other_params = True +# if cancelled is not None: +# req_url += f'{param_char(other_params)}cancelled={cancelled}' +# other_params = True +# +# resp = requests.patch(req_url, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_one_battingseason(player_id): +# req_url = f'{DB_URL}/v1/battingseasons/{player_id}' +# +# return await db_get(req_url) +# +# +# async def get_one_pitchingseason(player_id): +# req_url = f'{DB_URL}/v1/pitchingseasons/{player_id}' +# +# return await db_get(req_url) +# +# +# async def get_one_fieldingseason(player_id): +# req_url = f'{DB_URL}/v1/fieldingseasons/{player_id}' +# +# return await db_get(req_url) +# +# +# async def get_battingcareer(name_or_id): +# req_url = f'{DB_URL}/v1/battingcareer/{name_or_id}' +# +# return await db_get(req_url) +# +# +# async def get_pitchingcareer(name_or_id): +# req_url = f'{DB_URL}/v1/pitchingcareer/{name_or_id}' +# +# return await db_get(req_url) +# +# +# async def get_battingstat( +# season, s_type='regular', team_abbrev=None, player_name=None, player_id=None, week_start=None, +# week_end=None, game_num=None, position=None, timeout=10): +# req_url = f'{DB_URL}/v1/battingstats/s{season}/{s_type}' +# other_params = False +# if team_abbrev: +# req_url += f'{param_char(other_params)}team_abbrev={team_abbrev}' +# other_params = True +# if player_name: +# req_url += f'{param_char(other_params)}player_name={player_name}' +# other_params = True +# if player_id: +# req_url += f'{param_char(other_params)}player_id={player_id}' +# other_params = True +# if week_start: +# req_url += f'{param_char(other_params)}week_start={week_start}' +# other_params = True +# if week_end: +# req_url += f'{param_char(other_params)}week_end={week_end}' +# other_params = True +# if game_num: +# req_url += f'{param_char(other_params)}game_num={game_num}' +# other_params = True +# if position: +# req_url += f'{param_char(other_params)}position={position}' +# other_params = True +# +# return await db_get(req_url, timeout=timeout) +# +# +# async def post_battingstats(stats: list): +# req_url = f'{DB_URL}/v1/battingstats' +# data = { +# 'count': len(stats), +# 'stats': stats +# } +# payload = json.dumps(data) +# +# resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def delete_battingstats(game_obj: dict): +# req_url = f'{DB_URL}/v1/battingstats' +# payload = json.dumps(game_obj) +# +# resp = requests.delete(req_url, data=payload, headers=AUTH_TOKEN) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def recalc_batting_seasons(season, team_id): +# req_url = f'{DB_URL}/v1/battingseasons/recalculate?season={season}&team_id={team_id}' +# +# resp = requests.post(req_url, headers=AUTH_TOKEN, timeout=45) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def recalc_fielding_seasons(season, team_id): +# req_url = f'{DB_URL}/v1/fieldingseasons/recalculate?season={season}&team_id={team_id}' +# +# resp = requests.post(req_url, headers=AUTH_TOKEN, timeout=45) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_pitchingstat( +# season, s_type='regular', team_abbrev=None, player_name=None, player_id=None, week_start=None, +# week_end=None, game_num=None, timeout=10): +# req_url = f'{DB_URL}/v1/pitchingstats/s{season}/{s_type}' +# other_params = False +# if team_abbrev: +# req_url += f'{param_char(other_params)}team_abbrev={team_abbrev}' +# other_params = True +# if player_name: +# req_url += f'{param_char(other_params)}player_name={player_name}' +# other_params = True +# if player_id: +# req_url += f'{param_char(other_params)}player_id={player_id}' +# other_params = True +# if week_start: +# req_url += f'{param_char(other_params)}week_start={week_start}' +# other_params = True +# if game_num: +# req_url += f'{param_char(other_params)}game_num={game_num}' +# other_params = True +# if week_end: +# req_url += f'{param_char(other_params)}week_end={week_end}' +# other_params = True +# +# return await db_get(req_url, timeout=timeout) +# +# +# async def post_pitchingstats(stats: list): +# req_url = f'{DB_URL}/v1/pitchingstats' +# data = { +# 'count': len(stats), +# 'stats': stats +# } +# payload = json.dumps(data) +# +# resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def delete_pitchingstats(game_obj: dict): +# req_url = f'{DB_URL}/v1/pitchingstats' +# payload = json.dumps(game_obj) +# +# resp = requests.delete(req_url, data=payload, headers=AUTH_TOKEN) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def recalc_pitching_seasons(season, team_id): +# req_url = f'{DB_URL}/v1/pitchingseasons/recalculate?season={season}&team_id={team_id}' +# +# resp = requests.post(req_url, headers=AUTH_TOKEN, timeout=45) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_draftdata(): +# return await db_get('draftdata') +# +# +# async def patch_draftdata( +# currentpick=None, timer=None, pick_deadline=None, result_channel=None, ping_channel=None, pick_minutes=None): +# req_url = f'{DB_URL}/v1/draftdata' +# other_params = False +# if currentpick is not None: +# req_url += f'{param_char(other_params)}currentpick={currentpick}' +# other_params = True +# if timer is not None: +# req_url += f'{param_char(other_params)}timer={timer}' +# other_params = True +# if pick_deadline is not None: +# req_url += f'{param_char(other_params)}pick_deadline={pick_deadline}' +# other_params = True +# if result_channel is not None: +# req_url += f'{param_char(other_params)}result_channel={result_channel}' +# other_params = True +# if ping_channel is not None: +# req_url += f'{param_char(other_params)}ping_channel={ping_channel}' +# other_params = True +# if pick_minutes is not None: +# req_url += f'{param_char(other_params)}pick_minutes={pick_minutes}' +# other_params = True +# +# resp = requests.patch(req_url, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_draftpicks( +# season, owner_team=None, orig_owner_team=None, round_start=None, round_end=None, team_season=None, +# overall_start=None, overall_end=None): +# req_url = f'{DB_URL}/v1/draftpicks?season={season}' +# if owner_team: +# req_url += f'&owner_team_abbrev={owner_team["abbrev"]}' +# if orig_owner_team: +# req_url += f'&orig_team_abbrev={orig_owner_team["abbrev"]}' +# if round_start: +# req_url += f'&pick_round_start={round_start}' +# if round_end: +# req_url += f'&pick_round_end={round_end}' +# if team_season: +# req_url += f'&team_season={team_season}' +# if overall_start: +# req_url += f'&overall_start={overall_start}' +# if overall_end: +# req_url += f'&overall_end={overall_end}' +# +# return await db_get(req_url) +# +# +# async def get_one_draftpick_search(season, orig_owner_abbrev, round_num: int, team_season: int = None): +# req_url = f'{DB_URL}/v1/draftpicks?season={season}' +# req_url += f'&orig_team_abbrev={orig_owner_abbrev}' +# req_url += f'&pick_round_start={round_num}' +# req_url += f'&pick_round_end={round_num}' +# if team_season is not None: +# req_url += f'&team_season={team_season}' +# +# picks = await db_get(req_url) +# if len(picks) == 0: +# return None +# elif len(picks) == 1: +# for x in picks: +# return picks[x] +# +# +# async def get_one_draftpick_byid(pick_id: int): +# req_url = f'{DB_URL}/v1/draftpicks/{pick_id}' +# +# return await db_get(req_url) +# +# +# async def get_one_draftpick_byoverall(season: int, overall: int): +# req_url = f'{DB_URL}/v1/draftpicks?season={season}&overall={overall}' +# +# resp = await db_get(req_url) +# if len(resp) != 1: +# return None +# else: +# key = [*resp] +# return resp[key[0]] +# +# +# async def patch_draftpick( +# pick_id: int, overall: int = None, round: int = None, orig_owner_id: int = None, owner_id: int = None, +# season: int = None, player_id: int = None): +# req_url = f'{DB_URL}/v1/draftpicks/{pick_id}' +# other_params = False +# if overall is not None: +# req_url += f'{param_char(other_params)}overall={overall}' +# other_params = True +# if round is not None: +# req_url += f'{param_char(other_params)}round={round}' +# other_params = True +# if orig_owner_id is not None: +# req_url += f'{param_char(other_params)}orig_owner_id={orig_owner_id}' +# other_params = True +# if owner_id is not None: +# req_url += f'{param_char(other_params)}owner_id={owner_id}' +# other_params = True +# if season is not None: +# req_url += f'{param_char(other_params)}season={season}' +# other_params = True +# if player_id is not None: +# req_url += f'{param_char(other_params)}player_id={player_id}' +# other_params = True +# +# resp = requests.patch(req_url, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_awards(player_id=None, player_name=None, season=None): +# req_url = f'{DB_URL}/v1/awards' +# other_params = False +# if player_id: +# req_url += f'{param_char(other_params)}player_id={player_id}' +# other_params = True +# if player_name: +# req_url += f'{param_char(other_params)}player_name={player_name}' +# other_params = True +# if season: +# req_url += f'{param_char(other_params)}season={season}' +# other_params = True +# +# resp = requests.get(req_url, timeout=3) +# if resp.status_code == 200: +# return resp.json() +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def post_award(award: dict): +# req_url = f'{DB_URL}/v1/awards' +# award_model = { +# 'name': award['name'], +# 'season': award['season'], +# 'timing': award['timing'], +# } +# if award['manager1']: +# award_model['manager1_id'] = award['manager1']['id'] +# if award['manager2']: +# award_model['manager2_id'] = award['manager2']['id'] +# if award['player']: +# award_model['player_id'] = award['player']['id'] +# if award['team']: +# award_model['team_id'] = award['team']['id'] +# if award['image']: +# award_model['image'] = award['image'] +# +# payload_prep = {'count': 1, 'awards': [award_model]} +# payload = json.dumps(payload_prep) +# +# resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_one_manager(manager_name): +# req_url = f'{DB_URL}/v1/managers/{manager_name}' +# +# return await db_get(req_url) +# +# +# async def post_dice(dice_bag: list): +# req_url = f'{DB_URL}/v1/dice' +# dice_model = { +# 'count': len(dice_bag), +# 'rolls': dice_bag +# } +# +# payload = json.dumps(dice_model) +# +# resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_player_photo(player_name): +# req_url = f'https://www.thesportsdb.com/api/v1/json/1/searchplayers.php?p={player_name}' +# +# try: +# resp = requests.get(req_url, timeout=.5) +# except Exception as e: +# return None +# if resp.status_code == 200 and resp.json()['player']: +# if resp.json()['player'][0]['strSport'] == 'Baseball': +# return resp.json()['player'][0]['strThumb'] +# return None +# +# +# async def get_player_headshot(player_name): +# req_url = f'https://www.baseball-reference.com/search/search.fcgi?search={player_name}' +# +# try: +# resp = requests.get(req_url, timeout=1).text +# except Exception as e: +# return None +# soup = BeautifulSoup(resp, 'html.parser') +# for item in soup.find_all('img'): +# if 'headshot' in item['src']: +# return item['src'] +# return await get_player_photo(player_name) +# +# +# async def post_draft_list(this_list: list): +# req_url = f'{DB_URL}/v1/draft-list' +# list_model = { +# 'count': len(this_list), +# 'draft_list': this_list +# } +# +# payload = json.dumps(list_model) +# +# resp = requests.post(req_url, payload, headers=AUTH_TOKEN, timeout=3) +# if resp.status_code == 200: +# return True +# else: +# logging.warning(resp.text) +# raise ValueError(f'DB: {resp.text}') +# +# +# async def get_draft_list(team): +# req_url = f'{DB_URL}/v1/draft-list/{team["id"]}' +# +# return await db_get(req_url) diff --git a/helpers.py b/helpers.py index 5e55b6b..dfc0a64 100644 --- a/helpers.py +++ b/helpers.py @@ -2,7 +2,7 @@ import datetime import pygsheets -from db_calls import db_get, db_patch, db_post, db_delete, get_player_headshot +from db_calls import db_get, get_player_headshot, get_team_by_abbrev, get_team_by_owner # from db_calls import * import asyncio @@ -835,7 +835,7 @@ async def get_player_embed(player, current, ctx=None, season=None): if len(positions) > 0: embed.add_field(name=f'Position{"s" if len(positions) > 1 else ""}', value=",".join(positions)) if player['team']['abbrev'][-3:].lower() == 'mil': - major_team = await get_one_team(player['team']['abbrev'][:-3], season=player['season']) + major_team = await get_team_by_abbrev(player['team']['abbrev'][:-3], season=player['season']) embed.add_field(name='SBa Affiliate', value=major_team['sname']) if player['last_game']: embed.add_field(name='Last G', value=player['last_game']) @@ -987,7 +987,7 @@ async def create_channel( async def get_major_team(team): if 'Il' in team['abbrev'][len(team['abbrev']) - 2:].lower(): - return await get_one_team(team['abbrev'][:-2]) + return await get_team_by_abbrev(team['abbrev'][:-2], team['season']) else: return team