Skip to content

Commit

Permalink
Made timeout adjustable
Browse files Browse the repository at this point in the history
  • Loading branch information
mario872 committed Aug 21, 2024
1 parent 0cd3092 commit de93f2d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sentralify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .scrapers import scrapers
from .generators import generators

def sentralify(config: dict, timetable: bool = True, notices: bool = True, calendar: bool = True, persistent: bool = True, check_login: bool = False):
def sentralify(config: dict, timetable: bool = True, notices: bool = True, calendar: bool = True, persistent: bool = True, check_login: bool = False, timeout = 5000):
"""
Function to scrape Sentral
Expand All @@ -51,7 +51,7 @@ def sentralify(config: dict, timetable: bool = True, notices: bool = True, calen

# Initialise the generators and scrapers
Sentral = generators
scraper = scrapers(config)
scraper = scrapers(config, timeout=timeout)

if check_login: persistent = False

Expand Down
5 changes: 3 additions & 2 deletions sentralify/scrapers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Main scrapers class

class scrapers:
def __init__(self, config: dict):
def __init__(self, config: dict, timeout: int):
"""
Run on creation of scrapers class, initiates
config variable for the rest of the class
Expand All @@ -38,6 +38,7 @@ def __init__(self, config: dict):
"""

self.config = config
self.timeout = timeout

def check_login(self, browser):

Expand Down Expand Up @@ -107,7 +108,7 @@ def login(self, browser):
page.goto(f"https://{self.config['base_url']}.sentral.com.au/portal?action=login_student") # Go to main Sentral v2 portal login page

try: # If we have already signed in before, and the cookies haven't expired, then we will be redirected to the portal page automatically
expect(page).to_have_title(re.compile(f"Portal - {self.config['username'].split('.')[0]}", re.IGNORECASE), timeout=10000)
expect(page).to_have_title(re.compile(f"Portal - {self.config['username'].split('.')[0]}", re.IGNORECASE), timeout=self.timeout)
return page
except AssertionError: # Okay, we haven't logged in recently enough
pass
Expand Down

0 comments on commit de93f2d

Please sign in to comment.