diff options
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/aspen.py | 15 | ||||
-rw-r--r-- | libraries/polaris.py | 27 |
2 files changed, 41 insertions, 1 deletions
diff --git a/libraries/aspen.py b/libraries/aspen.py index bb430c3..21e0115 100644 --- a/libraries/aspen.py +++ b/libraries/aspen.py @@ -41,6 +41,7 @@ class Library(BaseLibrary): self.alias = config_obj["alias"] else: self.alias = alias if alias else "Aspen-based library" + self.card_expires = None # log in now. Why would we not? self.login() @@ -104,7 +105,6 @@ class Library(BaseLibrary): img_href = i.find("img")["src"] img_b64, img_type = self.get_image(img_href) if verbose: - #print(f"DEBUG available: item {i}", file=sys.stderr) print(f"DEBUG available: title {title_obj.text}", file=sys.stderr) print(f"DEBUG available: values_dict {values_dict}", file=sys.stderr) obj = { @@ -200,3 +200,16 @@ class Library(BaseLibrary): "Priority": "u=1" } s.post(f"{b}/MyAccount/Home", headers = headers, data = data) + # step 3: learn card expiration date + # curl 'https://aspen.example.org/MyAccount/AJAX?method=getMenuDataIls&activeModule=MyAccount&activeAction=CheckedOut' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: https://aspen.example.org/MyAccount/CheckedOut' -H 'Cookie: aspen_session=bksjhjndqhjcsoplci3b6htl3u' + params = { + "method": "getMenuDataIls", + "activeModule": "MyAccount", + "activeAction": "CheckedOut", + } + headers = { + "Referer": f"{b}/MyAccount/CheckedOut" + } + response = s.get(f"{b}/MyAccount/AJAX",params=params,headers=headers) + output = json.loads(response.content) + self.card_expires = dateutil.parser.parse(output["summary"]["expires"]) diff --git a/libraries/polaris.py b/libraries/polaris.py index 6fab43d..e945fcc 100644 --- a/libraries/polaris.py +++ b/libraries/polaris.py @@ -51,6 +51,7 @@ class Library(BaseLibrary): self.baseurl_http = self.baseurl.replace("https://","http://") self.src = f"{self.baseurl_http}/patronaccount/default.aspx?ctx={self.language_code}&ctx={self.language_code}" self.src2 = urllib.parse.unquote_plus(self.src) + self.card_expires = None # log in now. Why would we not? self.login() @@ -207,3 +208,29 @@ class Library(BaseLibrary): for msg in ["invalid Library Card", "Please enter your Library", "Please try again"]: if msg in response: raise Exception(f"Failed to log in to {self.alias}") + # step 3: learn card expiration date + # curl 'https://catalog.example.org/polaris/PatronAccount/default.aspx' -H 'Referer: https://catalog.example.org/polaris/PatronAccount/requests.aspx' -H 'Cookie: ASP.NET_SessionId=umyzdtvpkv5mo45axo3fny20; OrgID=1' + headers = { + "Referer": f"{b}/PatronAccount/requests.aspx" + } + output = s.get(f"{b}/PatronAccount/default.aspx",headers=headers).content + soup = BeautifulSoup(output, "html.parser") + alldivs = soup.find_all("div",class_="row") + labels = [] + values = [] + for i in alldivs: + j = i.find_all("span") + try: + # replace colon-nbsp from labels with empty + labels.append(j[0].text.replace(":\xa0","")) + except: + labels.append("empty") + try: + values.append(j[1].text) + except: + values.append("empty") + values_dict = dict(map(lambda i,j:(i,j),labels,values)) + if "Expiration date" not in values_dict: + print(f"Warning! Cannot determine expiration date for {self.alias}. Continuing.",file=sys.stderr) + else: + self.card_expires = dateutil.parser.parse(values_dict["Expiration date"]) |