diff options
author | B. Stack <bgstack15@gmail.com> | 2024-07-13 16:23:06 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2024-07-13 16:23:06 -0400 |
commit | c6ec4dd41d1b9569f5b37ee263c4d747c47e188e (patch) | |
tree | f8e76d74522c8aebe36674769951aca04c2aaf12 /libraries/polaris.py | |
parent | update cron-run script to use separate images for html (diff) | |
download | library-info-c6ec4dd41d1b9569f5b37ee263c4d747c47e188e.tar.gz library-info-c6ec4dd41d1b9569f5b37ee263c4d747c47e188e.tar.bz2 library-info-c6ec4dd41d1b9569f5b37ee263c4d747c47e188e.zip |
all libraries: collect card expiry date
Diffstat (limited to 'libraries/polaris.py')
-rw-r--r-- | libraries/polaris.py | 27 |
1 files changed, 27 insertions, 0 deletions
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"]) |