allow for storing season_slug, team_slug, team_id to client
This commit is contained in:
@@ -14,7 +14,10 @@ class GameChangerClient():
|
|||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
url = "https://gc.com/t/{season_slug}/{team_slug}-{team_id}/{page}"
|
url = "https://gc.com/t/{season_slug}/{team_slug}-{team_id}/{page}"
|
||||||
|
|
||||||
def __init__(self, email, password):
|
def __init__(self, email, password, season_slug=None, team_slug=None, team_id=None):
|
||||||
|
self.season_slug=season_slug
|
||||||
|
self.team_slug=team_slug
|
||||||
|
self.team_id=team_id
|
||||||
r = requests.get("https://gc.com/login")
|
r = requests.get("https://gc.com/login")
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
@@ -45,6 +48,17 @@ class GameChangerClient():
|
|||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def is_authorized(self):
|
||||||
|
login_url = "https://gc.com/login"
|
||||||
|
|
||||||
|
check = self.session.get(login_url)
|
||||||
|
|
||||||
|
# If authorized, the site will redirect away from login page
|
||||||
|
if check.url != login_url:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def _scrape_from_page_initialize_json(self, season_slug, team_id, team_slug, page):
|
def _scrape_from_page_initialize_json(self, season_slug, team_id, team_slug, page):
|
||||||
resp = self.session.get(
|
resp = self.session.get(
|
||||||
self.url.format(season_slug=season_slug, team_id=team_id, team_slug=team_slug, page=page)
|
self.url.format(season_slug=season_slug, team_id=team_id, team_slug=team_slug, page=page)
|
||||||
@@ -55,11 +69,17 @@ class GameChangerClient():
|
|||||||
m = initialize_page_json.group(1)
|
m = initialize_page_json.group(1)
|
||||||
return json.loads(m)
|
return json.loads(m)
|
||||||
|
|
||||||
def get_roster(self, season_slug, team_id, team_slug):
|
def get_roster(self, season_slug=None, team_id=None, team_slug=None):
|
||||||
|
if not season_slug: season_slug=self.season_slug
|
||||||
|
if not team_id: team_id=self.team_id
|
||||||
|
if not team_slug: team_slug=self.team_slug
|
||||||
data = self._scrape_from_page_initialize_json(season_slug, team_id, team_slug, "roster")
|
data = self._scrape_from_page_initialize_json(season_slug, team_id, team_slug, "roster")
|
||||||
return data['roster']
|
return data['roster']
|
||||||
|
|
||||||
def get_stats(self, season_slug, team_id, team_slug):
|
def get_stats(self, season_slug=None, team_id=None, team_slug=None):
|
||||||
|
if not season_slug: season_slug=self.season_slug
|
||||||
|
if not team_id: team_id=self.team_id
|
||||||
|
if not team_slug: team_slug=self.team_slug
|
||||||
resp = self.session.get(
|
resp = self.session.get(
|
||||||
self.url.format(
|
self.url.format(
|
||||||
page="stats/batting/Qualified/standard/csv",
|
page="stats/batting/Qualified/standard/csv",
|
||||||
@@ -122,7 +142,10 @@ class GameChangerClient():
|
|||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
def get_games(self, season_slug, team_id, team_slug):
|
def get_games(self, season_slug=None, team_id=None, team_slug=None):
|
||||||
|
if not season_slug: season_slug=self.season_slug
|
||||||
|
if not team_id: team_id=self.team_id
|
||||||
|
if not team_slug: team_slug=self.team_slug
|
||||||
page = self.session.get(
|
page = self.session.get(
|
||||||
url=self.url.format(
|
url=self.url.format(
|
||||||
page="schedule/games",
|
page="schedule/games",
|
||||||
@@ -149,7 +172,10 @@ class GameChangerClient():
|
|||||||
)
|
)
|
||||||
return games
|
return games
|
||||||
|
|
||||||
def submit_lineup(self, lineup, season_slug, team_slug, team_id):
|
def submit_lineup(self, lineup, season_slug=None, team_id=None, team_slug=None):
|
||||||
|
if not season_slug: season_slug=self.season_slug
|
||||||
|
if not team_id: team_id=self.team_id
|
||||||
|
if not team_slug: team_slug=self.team_slug
|
||||||
headers = self.session.headers
|
headers = self.session.headers
|
||||||
headers.update(
|
headers.update(
|
||||||
{
|
{
|
||||||
@@ -191,7 +217,10 @@ class GameChangerClient():
|
|||||||
game_stream = json.loads(stream_page.content)
|
game_stream = json.loads(stream_page.content)
|
||||||
return game_stream
|
return game_stream
|
||||||
|
|
||||||
def get_lineup(self, season_slug, team_slug, team_id):
|
def get_lineup(self, season_slug=None, team_id=None, team_slug=None):
|
||||||
|
if not season_slug: season_slug=self.season_slug
|
||||||
|
if not team_id: team_id=self.team_id
|
||||||
|
if not team_slug: team_slug=self.team_slug
|
||||||
resp = self.session.get(
|
resp = self.session.get(
|
||||||
self.url.format(
|
self.url.format(
|
||||||
page="lineup",
|
page="lineup",
|
||||||
|
|||||||
Reference in New Issue
Block a user