Skip to content

Commit

Permalink
Merge pull request #93 from amarvin/91-update-for-2024
Browse files Browse the repository at this point in the history
Updates public leagues for 2024
  • Loading branch information
amarvin authored Aug 15, 2024
2 parents 1621321 + e417d6a commit 3e8129c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ffbot/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from user_agent import generate_user_agent

# A public league for current week and player IDs
PUBLIC_LEAGUE = 16
PUBLIC_LEAGUE_IDP = 762
PUBLIC_LEAGUE = 101
PUBLIC_LEAGUE_IDP = 408
SEARCH_PLAYER_GROUPS = ["QB", "WR", "RB", "TE", "K", "DEF"]
SEARCH_PLAYER_GROUPS_IDP = ["QB", "WR", "RB", "TE", "K", "D", "DB", "DL", "LB"]

Expand Down
40 changes: 40 additions & 0 deletions find_public_league.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from io import StringIO
from time import sleep

from pandas import read_html

from ffbot.scraper import create_session, generate_user_agent

s = create_session()

found_public, found_public_idp = False, False
for public_league in range(0, 1000):
url = "https://football.fantasysports.yahoo.com/f1/{}/settings".format(
public_league
)
s.headers["User-Agent"] = generate_user_agent()
r = s.get(url)

# Parse tables from page, if tables exist (i.e. public league)
try:
dfs = read_html(StringIO(r.text))
except ValueError as e:
if str(e) == "No tables found":
print(f"{public_league} is not a valid public league")
sleep(10)
continue
else:
raise e

# Parse league settings to detect if is DEF or IDP
df = dfs[0]
positions = df.loc[df["Setting"] == "Roster\xa0Positions:", "Value"].iloc[0]
if "DEF" in positions:
found_public = True
print(f"{public_league} is a valid public league")
elif "DB" in positions:
found_public_idp = True
print(f"{public_league} is a valid public IDP league")

if found_public and found_public_idp:
break
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
black
flake8
isort[colors]
pandas[html]
pre-commit
pytest
pytest-cov

0 comments on commit 3e8129c

Please sign in to comment.