aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2024-07-13 16:23:06 -0400
committerB. Stack <bgstack15@gmail.com>2024-07-13 16:23:06 -0400
commitc6ec4dd41d1b9569f5b37ee263c4d747c47e188e (patch)
treef8e76d74522c8aebe36674769951aca04c2aaf12
parentupdate cron-run script to use separate images for html (diff)
downloadlibrary-info-c6ec4dd41d1b9569f5b37ee263c4d747c47e188e.tar.gz
library-info-c6ec4dd41d1b9569f5b37ee263c4d747c47e188e.tar.bz2
library-info-c6ec4dd41d1b9569f5b37ee263c4d747c47e188e.zip
all libraries: collect card expiry date
-rw-r--r--.gitignore1
-rw-r--r--.useful1
-rw-r--r--libraries/aspen.py15
-rw-r--r--libraries/polaris.py27
-rwxr-xr-xlibrary_info_cli.py1
5 files changed, 44 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index f801c4e..7e67ca0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
__pycache__/
config.py
*.html
+.*.swp
diff --git a/.useful b/.useful
new file mode 100644
index 0000000..344dbd5
--- /dev/null
+++ b/.useful
@@ -0,0 +1 @@
+vi $( find . ! -type d ! -name *.pyc ! -path */.git/* | sort )
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"])
diff --git a/library_info_cli.py b/library_info_cli.py
index 1de3cf3..cf80043 100755
--- a/library_info_cli.py
+++ b/library_info_cli.py
@@ -64,6 +64,7 @@ def html_td_img(i, imagepath, imagerelativepath):
return "<td>none</td>"
def html(checkouts, reservations, imagepath, imagerelativepath):
+ # WORKHERE: need to revise this to take a list of config entries to load, so we can collect card expiration info
"""
Make a pretty html page of the items. If imagepath and imagerelativepath are defined, save the images to imagepath, and set the html img tags src attribute to the imagerelativepath.
"""
bgstack15