Add get_teams

This commit is contained in:
2022-06-25 09:07:09 -05:00
parent 32c6038d3f
commit 8a1ad6bb7e

View File

@@ -252,3 +252,30 @@ class GameChangerClient():
lineup.insert(dh_index+1, d)
return lineup
def get_teams(self):
url = "https://gc.com/account/teams"
page = self.session.get(url=url)
soup = BeautifulSoup(page.content, "html.parser")
team_elements = [i for i in soup.find_all("li") if i.attrs.get("data-team-id")]
teams = []
for i, team_element in enumerate(team_elements):
league_type, number_of_games = [
c.text.strip() for c in team_element.findChildren("li")
][1:3]
season_slug, team_slug = (
team_element.find("a").attrs.get("href", "///").split("/")[2:]
)
teams.append(
{
"name": team_element.find("a").text,
"id": team_element.attrs.get("data-team-id"),
"season": team_element.findPrevious("header").text,
"league_type": league_type,
"number_of_games": number_of_games,
"season_slug": season_slug,
"team_slug": team_slug,
}
)
return teams