Delete wip.ipynb
This commit is contained in:
parent
f8ef55628c
commit
082f905a25
172
wip.ipynb
172
wip.ipynb
|
|
@ -1,172 +0,0 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from argparse import ArgumentParser\n",
|
||||
"from config import Config as cfg\n",
|
||||
"from datetime import datetime\n",
|
||||
"from espn_api.football import League\n",
|
||||
"from gspread_dataframe import get_as_dataframe, set_with_dataframe\n",
|
||||
"from service import gc\n",
|
||||
"from time import strftime\n",
|
||||
"\n",
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def check_int(s):\n",
|
||||
" if s is None:\n",
|
||||
" return s\n",
|
||||
" if s[0] in ('-', '+'):\n",
|
||||
" return s[1:].isdigit()\n",
|
||||
" return s.isdigit()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def extract_positional_data(lineup: list, position: str) -> int:\n",
|
||||
" response = 0\n",
|
||||
" for player in lineup:\n",
|
||||
" if player.lineupSlot == position:\n",
|
||||
" response = response + player.points\n",
|
||||
" return response\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def extract_matchup_box_scores(league: League) -> dict:\n",
|
||||
" result = []\n",
|
||||
" for week in range(1, league.current_week + 1):\n",
|
||||
" matchups = league.box_scores(week=week)\n",
|
||||
" for matchup in matchups:\n",
|
||||
" result.append({\n",
|
||||
" 'WEEK #': week,\n",
|
||||
" 'AWAY TEAM': matchup.away_team.team_name,\n",
|
||||
" 'AWAY TEAM SCORE': matchup.away_score,\n",
|
||||
" 'AWAY TEAM KICKER': extract_positional_data(matchup.away_lineup, 'K'),\n",
|
||||
" 'AWAY TEAM BENCH': extract_positional_data(matchup.away_lineup, 'BE'),\n",
|
||||
" 'HOME TEAM': matchup.home_team.team_name,\n",
|
||||
" 'HOME TEAM SCORE': matchup.home_score,\n",
|
||||
" 'HOME TEAM KICKER': extract_positional_data(matchup.home_lineup, 'K'),\n",
|
||||
" 'HOME TEAM BENCH': extract_positional_data(matchup.home_lineup, 'BE')\n",
|
||||
" })\n",
|
||||
" return result\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def write_to_google_spreadsheet(df: pd.DataFrame):\n",
|
||||
" spreadsheet = gc.open_by_key(cfg.SPREADSHEET_ID)\n",
|
||||
" worksheet = spreadsheet.worksheet(\"FantasyData\")\n",
|
||||
" set_with_dataframe(worksheet, df)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"league = League(league_id=cfg.LEAGUE_ID, \n",
|
||||
" year=datetime.now().year, \n",
|
||||
" espn_s2=cfg.ESPN_S2, \n",
|
||||
" swid=cfg.SWID, \n",
|
||||
" fetch_league=cfg.FETCH_LEAGUE)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"matchup = extract_matchup_box_scores(league=league)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df = pd.DataFrame.from_dict(matchup) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#spreadsheet = gc.open_by_key(cfg.SPREADSHEET_ID)\n",
|
||||
"spreadsheet = gc.open_by_key('1vBtceabKqc0QAs7MOgeg-q0FSHXIbNf31B8XEgzy6s8')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"worksheet = spreadsheet.worksheet(\"FantasyData\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"set_with_dataframe(worksheet, df)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def next_available_row(worksheet):\n",
|
||||
" str_list = list(filter(None, worksheet.col_values(1)))\n",
|
||||
" return str(len(str_list)+1)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'7'"
|
||||
]
|
||||
},
|
||||
"execution_count": 24,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"next_available_row(worksheet=worksheet)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"name": "python",
|
||||
"version": "3.10.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Loading…
Reference in a new issue