Awaiting db_calls
This commit is contained in:
parent
b705a35911
commit
cce74c4f92
@ -133,7 +133,7 @@ class Players(commands.Cog):
|
||||
current = await get_current()
|
||||
logging.info(f'build_master_player_list - getting all_players')
|
||||
# all_players = await get_players(current['season'])
|
||||
all_players = db_get('players', api_ver=2, timeout=8, params=[('season', current['season'])])
|
||||
all_players = await db_get('players', api_ver=2, timeout=8, params=[('season', current['season'])])
|
||||
logging.info(f'build_master_player_list - building player_list')
|
||||
self.player_list = {all_players[player]['name'].lower(): all_players[player]['id'] for player in all_players}
|
||||
logging.info(f'player list count: {len(self.player_list)}')
|
||||
@ -2929,7 +2929,7 @@ class Players(commands.Cog):
|
||||
keeper_swar += this_p['wara']
|
||||
|
||||
await interaction.response.send_message(content=f'{team["sname"]} Keepers:\n{keeper_string}')
|
||||
all_players = db_get('players', api_ver=2, params=[('team_abbrev', team['abbrev'])])
|
||||
all_players = await db_get('players', api_ver=2, params=[('team_abbrev', team['abbrev'])])
|
||||
logging.info(f'all_players: {all_players}')
|
||||
|
||||
fa = await get_one_team('FA')
|
||||
|
||||
@ -598,7 +598,7 @@ class Transactions(commands.Cog):
|
||||
# csv = DataFrame(csv_data).to_csv(header=False, index=False)
|
||||
# csv = pandas.read_csv(csv_data)
|
||||
|
||||
ap = db_get('players', api_ver=2, timeout=8, params=[('season', season)])
|
||||
ap = await db_get('players', api_ver=2, timeout=8, params=[('season', season)])
|
||||
player_data = [
|
||||
['name', 'sWAR', 'image', 'vanity_card', 'team_abbrev', 'inj_rat', 'pos_1', 'pos_2', 'pos_3', 'pos_4',
|
||||
'pos_5', 'pos_6', 'pos_7', 'pos_8', 'last_game', 'last_game2', 'il_return', 'dem_week', 'strat_code',
|
||||
|
||||
402
db_calls.py
402
db_calls.py
@ -19,7 +19,10 @@ def param_char(other_params):
|
||||
return '?'
|
||||
|
||||
|
||||
def get_req_url(endpoint: str, api_ver: int = 1, object_id: str = None, params: list = None):
|
||||
def get_req_url(endpoint: str, api_ver: int = 1, object_id: int = None, params: list = None):
|
||||
# Checking for hard-coded url
|
||||
if '/api/' in endpoint:
|
||||
return endpoint
|
||||
req_url = f'{DB_URL}/v{api_ver}/{endpoint}{"/" if object_id is not None else ""}{object_id if object_id is not None else ""}'
|
||||
|
||||
if params:
|
||||
@ -31,18 +34,24 @@ def get_req_url(endpoint: str, api_ver: int = 1, object_id: str = None, params:
|
||||
return req_url
|
||||
|
||||
|
||||
def db_get(endpoint: str, api_ver: int = 1, object_id: int = None, params: list = None, none_okay: bool = True,
|
||||
timeout: int = 3):
|
||||
async def db_get(endpoint: str, api_ver: int = 1, object_id: int = None, params: list = None, none_okay: bool = True,
|
||||
timeout: int = 3):
|
||||
req_url = get_req_url(endpoint, api_ver=api_ver, object_id=object_id, params=params)
|
||||
log_string = f'get:\n{endpoint} id: {object_id} params: {params}'
|
||||
logging.info(log_string) if master_debug else logging.debug(log_string)
|
||||
|
||||
try:
|
||||
resp = requests.get(req_url, timeout=timeout)
|
||||
except requests.ReadTimeout as e:
|
||||
logging.error(f'Read Timeout: {e}')
|
||||
raise ConnectionError(f'DB: The internet was a bit too slow for me to grab the data I needed. Please '
|
||||
f'hang on a few extra seconds and try again.')
|
||||
retries = 0
|
||||
while True:
|
||||
try:
|
||||
resp = requests.get(req_url, timeout=timeout)
|
||||
break
|
||||
except requests.ReadTimeout as e:
|
||||
logging.error(f'Get Timeout: {req_url} / retries: {retries} / timeout: {timeout}')
|
||||
if retries > 1:
|
||||
raise ConnectionError(f'DB: The internet was a bit too slow for me to grab the data I needed. Please '
|
||||
f'hang on a few extra seconds and try again.')
|
||||
timeout += [2, 5][retries]
|
||||
retries += 1
|
||||
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
@ -65,94 +74,154 @@ def db_get(endpoint: str, api_ver: int = 1, object_id: int = None, params: list
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
|
||||
|
||||
async def get_current(season=None):
|
||||
req_url = f'{DB_URL}/v1/current'
|
||||
if season:
|
||||
req_url += f'?season={season}'
|
||||
async def db_patch(endpoint: str, object_id: int, params: list, api_ver: int = 1, timeout: int = 3):
|
||||
req_url = get_req_url(endpoint, api_ver=api_ver, object_id=object_id, params=params)
|
||||
log_string = f'patch:\n{endpoint} {params}'
|
||||
logging.info(log_string) if master_debug else logging.debug(log_string)
|
||||
|
||||
retries = 0
|
||||
while True:
|
||||
try:
|
||||
resp = requests.patch(req_url, headers=AUTH_TOKEN, timeout=timeout)
|
||||
break
|
||||
except requests.Timeout as e:
|
||||
logging.error(f'Patch Timeout: {req_url} / retries: {retries} / timeout: {timeout}')
|
||||
if retries > 1:
|
||||
raise ConnectionError(f'DB: The internet was a bit too slow for me to grab the data I needed. Please '
|
||||
f'hang on a few extra seconds and try again.')
|
||||
timeout += [min(3, timeout), min(5, timeout)][retries]
|
||||
retries += 1
|
||||
|
||||
resp = requests.get(req_url)
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
data = resp.json()
|
||||
log_string = f'{data}'
|
||||
if master_debug:
|
||||
logging.info(f'return: {log_string[:1200]}{" [ S N I P P E D ]" if len(log_string) > 1200 else ""}')
|
||||
else:
|
||||
logging.debug(f'return: {log_string[:1200]}{" [ S N I P P E D ]" if len(log_string) > 1200 else ""}')
|
||||
return data
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
|
||||
|
||||
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):
|
||||
req_url = f'{DB_URL}/v1/current'
|
||||
other_params = False
|
||||
if week:
|
||||
req_url += f'{param_char(other_params)}week={week}'
|
||||
other_params = True
|
||||
if freeze is not None:
|
||||
req_url += f'{param_char(other_params)}freeze={freeze}'
|
||||
other_params = True
|
||||
if season:
|
||||
req_url += f'{param_char(other_params)}season={season}'
|
||||
other_params = True
|
||||
if transcount:
|
||||
req_url += f'{param_char(other_params)}transcount={transcount}'
|
||||
other_params = True
|
||||
if bstatcount:
|
||||
req_url += f'{param_char(other_params)}bstatcount={bstatcount}'
|
||||
other_params = True
|
||||
if pstatcount:
|
||||
req_url += f'{param_char(other_params)}pstatcount={pstatcount}'
|
||||
other_params = True
|
||||
if bet_week:
|
||||
req_url += f'{param_char(other_params)}bet_week={bet_week}'
|
||||
other_params = True
|
||||
if trade_deadline:
|
||||
req_url += f'{param_char(other_params)}trade_deadline={trade_deadline}'
|
||||
other_params = True
|
||||
if pick_trade_start:
|
||||
req_url += f'{param_char(other_params)}pick_trade_start={pick_trade_start}'
|
||||
other_params = True
|
||||
if pick_trade_end:
|
||||
req_url += f'{param_char(other_params)}pick_trade_end={pick_trade_end}'
|
||||
other_params = True
|
||||
if injury_count:
|
||||
req_url += f'{param_char(other_params)}injury_count={injury_count}'
|
||||
other_params = True
|
||||
async def db_post(endpoint: str, api_ver: int = 1, payload: dict = None, timeout: int = 3):
|
||||
req_url = get_req_url(endpoint, api_ver=api_ver)
|
||||
log_string = f'post:\n{endpoint} payload: {payload}\ntype: {type(payload)}'
|
||||
logging.info(log_string) if master_debug else logging.debug(log_string)
|
||||
|
||||
retries = 0
|
||||
while True:
|
||||
try:
|
||||
resp = requests.post(req_url, json=payload, headers=AUTH_TOKEN, timeout=timeout)
|
||||
break
|
||||
except requests.Timeout as e:
|
||||
logging.error(f'Post Timeout: {req_url} / retries: {retries} / timeout: {timeout}')
|
||||
if retries > 1:
|
||||
raise ConnectionError(f'DB: The internet was a bit too slow for me to grab the data I needed. Please '
|
||||
f'hang on a few extra seconds and try again.')
|
||||
timeout += [min(3, timeout), min(5, timeout)][retries]
|
||||
retries += 1
|
||||
|
||||
resp = requests.patch(req_url, data=None, headers=AUTH_TOKEN, timeout=3)
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
log_string = f'{data}'
|
||||
if master_debug:
|
||||
logging.info(f'return: {log_string[:1200]}{" [ S N I P P E D ]" if len(log_string) > 1200 else ""}')
|
||||
else:
|
||||
logging.debug(f'return: {log_string[:1200]}{" [ S N I P P E D ]" if len(log_string) > 1200 else ""}')
|
||||
return data
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
|
||||
|
||||
async def db_delete(endpoint: str, object_id: int, api_ver: int = 1, timeout=3):
|
||||
req_url = get_req_url(endpoint, api_ver=api_ver, object_id=object_id)
|
||||
log_string = f'delete:\n{endpoint} {object_id}'
|
||||
logging.info(log_string) if master_debug else logging.debug(log_string)
|
||||
|
||||
retries = 0
|
||||
while True:
|
||||
try:
|
||||
resp = requests.delete(req_url, headers=AUTH_TOKEN, timeout=timeout)
|
||||
break
|
||||
except requests.ReadTimeout as e:
|
||||
logging.error(f'Delete Timeout: {req_url} / retries: {retries} / timeout: {timeout}')
|
||||
if retries > 1:
|
||||
raise ConnectionError(f'DB: The internet was a bit too slow for me to grab the data I needed. Please '
|
||||
f'hang on a few extra seconds and try again.')
|
||||
timeout += [min(3, timeout), min(5, timeout)][retries]
|
||||
retries += 1
|
||||
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
log_string = f'{data}'
|
||||
if master_debug:
|
||||
logging.info(f'return: {log_string[:1200]}{" [ S N I P P E D ]" if len(log_string) > 1200 else ""}')
|
||||
else:
|
||||
logging.debug(f'return: {log_string[:1200]}{" [ S N I P P E D ]" if len(log_string) > 1200 else ""}')
|
||||
return True
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
|
||||
|
||||
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):
|
||||
current = await db_get('current')
|
||||
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))
|
||||
|
||||
return db_patch('current', object_id=current['id'], params=params)
|
||||
|
||||
|
||||
async def get_one_team(id_or_abbrev, season=None, is_pd=False, timeout=3):
|
||||
if is_pd:
|
||||
req_url = f'http://pd-database/api/v1/teams/{id_or_abbrev}'
|
||||
if season is not None:
|
||||
params = [('season', season)]
|
||||
else:
|
||||
req_url = f'{DB_URL}/v1/teams/{id_or_abbrev}'
|
||||
if season:
|
||||
req_url += f'?season={season}'
|
||||
params = None
|
||||
|
||||
resp = requests.get(req_url, timeout=timeout)
|
||||
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return await db_get('teams', object_id=id_or_abbrev, params=params)
|
||||
|
||||
|
||||
async def get_team_by_owner(season, owner_id):
|
||||
resp = requests.get(f'{DB_URL}/v1/teams?season={season}&owner_id={owner_id}&active_only=True', timeout=3)
|
||||
if resp.status_code == 200:
|
||||
full_resp = resp.json()
|
||||
if len(full_resp['teams']) != 1:
|
||||
raise ValueError(f'One team requested, but {len(full_resp)} were returned')
|
||||
else:
|
||||
return full_resp['teams'][0]
|
||||
params = [('active_only', True), ('season', season), ('owner_id', owner_id)]
|
||||
resp = await db_get('teams', params=params)
|
||||
if resp['count'] > 0:
|
||||
return resp['teams'][0]
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return None
|
||||
|
||||
|
||||
async def post_team(team):
|
||||
@ -240,12 +309,7 @@ async def get_schedule(
|
||||
if week_end:
|
||||
req_url += f'&week_end={week_end}'
|
||||
|
||||
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}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def get_one_schedule(
|
||||
@ -263,20 +327,15 @@ async def get_one_schedule(
|
||||
req_url += f'&week_start={week}'
|
||||
req_url += f'&week_end={week}'
|
||||
|
||||
resp = requests.get(req_url, timeout=3)
|
||||
if resp.status_code == 200:
|
||||
full_resp = resp.json()
|
||||
if len(full_resp) > 2:
|
||||
raise ValueError(f'One schedule requested, but {len(full_resp)} were returned')
|
||||
elif len(full_resp) == 0:
|
||||
raise ValueError(f'No schedules found')
|
||||
else:
|
||||
key = [*full_resp]
|
||||
return_val = full_resp[key[0]]
|
||||
return return_val
|
||||
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:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
key = [*resp]
|
||||
return_val = resp[key[0]]
|
||||
return return_val
|
||||
|
||||
|
||||
async def post_players(all_players: list):
|
||||
@ -303,12 +362,7 @@ async def get_players(season, team_abbrev=None, sort=None, injured=None):
|
||||
if injured:
|
||||
req_url += f'&injured={injured}'
|
||||
|
||||
resp = requests.get(req_url, timeout=6)
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def get_one_player(id_or_name, season=None):
|
||||
@ -316,12 +370,7 @@ async def get_one_player(id_or_name, season=None):
|
||||
if season is not None:
|
||||
req_url += f'?season={season}'
|
||||
|
||||
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}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def patch_player(
|
||||
@ -484,12 +533,7 @@ async def get_standings(season=None, team_abbrev=None, league_abbrev=None, divis
|
||||
req_url += f'{param_char(other_params)}division_abbrev={division_abbrev}'
|
||||
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}')
|
||||
resp = await db_get(req_url)
|
||||
|
||||
|
||||
async def post_standings_recalc(season):
|
||||
@ -515,12 +559,7 @@ async def get_results(season, team_abbrev=None, week=None, away_abbrev=None, hom
|
||||
if home_abbrev:
|
||||
req_url += f'&home_abbrev={home_abbrev}'
|
||||
|
||||
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}')
|
||||
resp = await db_get(req_url)
|
||||
|
||||
|
||||
async def post_result(result):
|
||||
@ -585,12 +624,7 @@ async def get_transactions(
|
||||
if move_id:
|
||||
req_url += f'&move_id={move_id}'
|
||||
|
||||
resp = requests.get(req_url, timeout=timeout)
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def post_transactions(moves: list):
|
||||
@ -630,60 +664,31 @@ async def patch_transaction(move_id, frozen=None, cancelled=None):
|
||||
async def get_one_battingseason(player_id):
|
||||
req_url = f'{DB_URL}/v1/battingseasons/{player_id}'
|
||||
|
||||
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}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def get_one_pitchingseason(player_id):
|
||||
req_url = f'{DB_URL}/v1/pitchingseasons/{player_id}'
|
||||
|
||||
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}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def get_one_fieldingseason(player_id):
|
||||
req_url = f'{DB_URL}/v1/fieldingseasons/{player_id}'
|
||||
|
||||
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}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def get_battingcareer(name_or_id):
|
||||
req_url = f'{DB_URL}/v1/battingcareer/{name_or_id}'
|
||||
|
||||
resp = requests.get(req_url, timeout=3)
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
elif resp.status_code == 404:
|
||||
return None
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def get_pitchingcareer(name_or_id):
|
||||
req_url = f'{DB_URL}/v1/pitchingcareer/{name_or_id}'
|
||||
|
||||
resp = requests.get(req_url, timeout=3)
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
elif resp.status_code == 404:
|
||||
return None
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def get_battingstat(
|
||||
@ -713,12 +718,7 @@ async def get_battingstat(
|
||||
req_url += f'{param_char(other_params)}position={position}'
|
||||
other_params = True
|
||||
|
||||
resp = requests.get(req_url, timeout=timeout)
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return await db_get(req_url, timeout=timeout)
|
||||
|
||||
|
||||
async def post_battingstats(stats: list):
|
||||
@ -795,12 +795,7 @@ async def get_pitchingstat(
|
||||
req_url += f'{param_char(other_params)}week_end={week_end}'
|
||||
other_params = True
|
||||
|
||||
resp = requests.get(req_url, timeout=timeout)
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return await db_get(req_url, timeout=timeout)
|
||||
|
||||
|
||||
async def post_pitchingstats(stats: list):
|
||||
@ -843,12 +838,7 @@ async def recalc_pitching_seasons(season, team_id):
|
||||
|
||||
|
||||
async def get_draftdata():
|
||||
resp = requests.get(f'{DB_URL}/v1/draftdata')
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return await db_get('draftdata')
|
||||
|
||||
|
||||
async def patch_draftdata(
|
||||
@ -901,12 +891,7 @@ async def get_draftpicks(
|
||||
if overall_end:
|
||||
req_url += f'&overall_end={overall_end}'
|
||||
|
||||
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}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def get_one_draftpick_search(season, orig_owner_abbrev, round_num: int, team_season: int = None):
|
||||
@ -917,44 +902,29 @@ async def get_one_draftpick_search(season, orig_owner_abbrev, round_num: int, te
|
||||
if team_season is not None:
|
||||
req_url += f'&team_season={team_season}'
|
||||
|
||||
resp = requests.get(req_url, timeout=3)
|
||||
if resp.status_code == 200:
|
||||
picks = resp.json()
|
||||
if len(picks) == 0:
|
||||
return None
|
||||
elif len(picks) == 1:
|
||||
for x in picks:
|
||||
return picks[x]
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
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}'
|
||||
|
||||
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}')
|
||||
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 = requests.get(req_url, timeout=3)
|
||||
if resp.status_code == 200:
|
||||
full_resp = resp.json()
|
||||
if len(full_resp) != 1:
|
||||
return None
|
||||
else:
|
||||
key = [*full_resp]
|
||||
return full_resp[key[0]]
|
||||
resp = await db_get(req_url)
|
||||
if len(resp) != 1:
|
||||
return None
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
key = [*resp]
|
||||
return resp[key[0]]
|
||||
|
||||
|
||||
async def patch_draftpick(
|
||||
@ -1042,12 +1012,7 @@ async def post_award(award: dict):
|
||||
async def get_one_manager(manager_name):
|
||||
req_url = f'{DB_URL}/v1/managers/{manager_name}'
|
||||
|
||||
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}')
|
||||
return await db_get(req_url)
|
||||
|
||||
|
||||
async def post_dice(dice_bag: list):
|
||||
@ -1114,9 +1079,4 @@ async def post_draft_list(this_list: list):
|
||||
async def get_draft_list(team):
|
||||
req_url = f'{DB_URL}/v1/draft-list/{team["id"]}'
|
||||
|
||||
resp = requests.get(req_url, headers=AUTH_TOKEN, timeout=3)
|
||||
if resp.status_code == 200:
|
||||
return resp.json()
|
||||
else:
|
||||
logging.warning(resp.text)
|
||||
raise ValueError(f'DB: {resp.text}')
|
||||
return await db_get(req_url)
|
||||
|
||||
@ -50,7 +50,7 @@ INFIELD_X_CHART = {
|
||||
'rp': 'No effect; proceed with speed check',
|
||||
'e1': 'Single and Error, batter to second, runners advance 2 bases.',
|
||||
'e2': 'Single and Error, batter to third, all runners score.',
|
||||
'no': 'Speed check, safe range equals batter\'s running rating'
|
||||
'no': 'Speed check, safe range equals batter\'s running rating, SI* result if safe, gb C if out'
|
||||
},
|
||||
'po': {
|
||||
'rp': 'The batters hits a popup. None of the fielders take charge on the play and the ball drops in the '
|
||||
|
||||
Loading…
Reference in New Issue
Block a user