From 8a1ad6bb7e9d0f3ddd15294045d777d273d11ee1 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 25 Jun 2022 09:07:09 -0500 Subject: [PATCH] Add get_teams --- gamescrapyr/gamescrapyr.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/gamescrapyr/gamescrapyr.py b/gamescrapyr/gamescrapyr.py index ae2db1f..41a9beb 100644 --- a/gamescrapyr/gamescrapyr.py +++ b/gamescrapyr/gamescrapyr.py @@ -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