|
|
|
@@ -1,3 +1,4 @@
|
|
|
|
|
#!/usr/bin/python3
|
|
|
|
|
import requests
|
|
|
|
|
import datetime
|
|
|
|
|
from tabulate import tabulate
|
|
|
|
@@ -5,6 +6,8 @@ import boto3
|
|
|
|
|
import json
|
|
|
|
|
from json import JSONEncoder
|
|
|
|
|
import logging
|
|
|
|
|
import re
|
|
|
|
|
from zoneinfo import ZoneInfo
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
class libaccount(dict):
|
|
|
|
|
def __init__(self,name,barcode,pin):
|
|
|
|
@@ -15,14 +18,13 @@ class libaccount(dict):
|
|
|
|
|
def toJson(self):
|
|
|
|
|
return json.dumps(self,default=lambda o: o.__dict__)
|
|
|
|
|
class book():
|
|
|
|
|
def __init__(self,itemid,renewalcount,checkoutdate,duedate,vendor,resourceid,resourceinstanceid,title,materialtype,coverurl,person,authsession,renewresult,overdue,isbn):
|
|
|
|
|
def __init__(self,itemid,renewalcount,checkoutdate,duedate,vendor,resourceid,title,materialtype,coverurl,person,authsession,renewresult,overdue,isbn,isill):
|
|
|
|
|
self.id=itemid
|
|
|
|
|
self.renewalcount=renewalcount
|
|
|
|
|
self.checkoutdate=checkoutdate
|
|
|
|
|
self.duedate=duedate
|
|
|
|
|
self.vendor=vendor
|
|
|
|
|
self.resourceid=resourceid
|
|
|
|
|
self.resourceinstanceid=resourceinstanceid
|
|
|
|
|
self.title=title
|
|
|
|
|
self.materialtype=materialtype
|
|
|
|
|
self.coverurl=coverurl
|
|
|
|
@@ -31,6 +33,7 @@ class book():
|
|
|
|
|
self.renewresult=renewresult
|
|
|
|
|
self.overdue=overdue
|
|
|
|
|
self.isbn=isbn
|
|
|
|
|
self.isill=isill
|
|
|
|
|
#self.ill=ill
|
|
|
|
|
def print(self):
|
|
|
|
|
print(self.person, self.id, self.title, self.checkoutdate, self.renewalcount, self.duedate, self.materialtype,self.renewresult, self.isbn)
|
|
|
|
@@ -128,6 +131,7 @@ for myaccount in accounts:
|
|
|
|
|
outs = session.get(checkoutsuri)
|
|
|
|
|
if len(outs.json()) >=1:
|
|
|
|
|
for mybook in outs.json():
|
|
|
|
|
isill=False
|
|
|
|
|
if mybook['vendor']=='overdrive':
|
|
|
|
|
continue
|
|
|
|
|
if mybook['vendor']=='hoopla':
|
|
|
|
@@ -135,7 +139,18 @@ for myaccount in accounts:
|
|
|
|
|
try:
|
|
|
|
|
myisbn = mybook['resource']['coverUrl']['small'].split('=')[1].split("/")[0]
|
|
|
|
|
except:
|
|
|
|
|
myisbn=''
|
|
|
|
|
myisbn=''
|
|
|
|
|
if myisbn=='':
|
|
|
|
|
if re.match(".*ILL",mybook['resource']['title']):
|
|
|
|
|
isill=True
|
|
|
|
|
try:
|
|
|
|
|
mycoverurl = mybook['resource']['coverUrl']['small']
|
|
|
|
|
except:
|
|
|
|
|
mycoverurl = ''
|
|
|
|
|
try:
|
|
|
|
|
myresourceid=mybook['resource']['id']
|
|
|
|
|
except:
|
|
|
|
|
myresourceid=''
|
|
|
|
|
duedate = datetime.datetime.strptime(mybook['dueDate'].split('T')[0],'%Y-%m-%d').date()
|
|
|
|
|
if datetime.date.today() > duedate:
|
|
|
|
|
overdue=True
|
|
|
|
@@ -148,16 +163,16 @@ for myaccount in accounts:
|
|
|
|
|
datetime.datetime.strptime(mybook['checkOutDate'].split('T')[0],'%Y-%m-%d').date(),
|
|
|
|
|
duedate,
|
|
|
|
|
mybook['vendor'],
|
|
|
|
|
mybook['resource']['id'],
|
|
|
|
|
mybook['resource']['instanceId'],
|
|
|
|
|
myresourceid,
|
|
|
|
|
mybook['resource']['title'],
|
|
|
|
|
mybook['resource']['materialType'],
|
|
|
|
|
mybook['resource']['coverUrl']['small'],
|
|
|
|
|
mycoverurl,
|
|
|
|
|
account.name,
|
|
|
|
|
session,
|
|
|
|
|
'None',
|
|
|
|
|
overdue,
|
|
|
|
|
myisbn
|
|
|
|
|
myisbn,
|
|
|
|
|
isill
|
|
|
|
|
)
|
|
|
|
|
if thisbook.materialtype in mediatypes:
|
|
|
|
|
pass
|
|
|
|
@@ -165,7 +180,6 @@ for myaccount in accounts:
|
|
|
|
|
mediatypes.append(thisbook.materialtype)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e,mybook)
|
|
|
|
|
|
|
|
|
|
allbooks.append(thisbook)
|
|
|
|
|
for book in allbooks:
|
|
|
|
|
#print(datetime.date.today(),book.duedate)
|
|
|
|
@@ -184,10 +198,9 @@ TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; b
|
|
|
|
|
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
|
|
|
|
|
</style><table>"""
|
|
|
|
|
tableend="</table> </body></html>"
|
|
|
|
|
|
|
|
|
|
returntable="Last Updated" + str(datetime.datetime.now())
|
|
|
|
|
returntable+='<br>Click <a href="https://librarynotice.hamik.net">Here</a> to be able to refresh the list.'
|
|
|
|
|
returntable+='<br>Click for the <a href="https://librarynotice.hamik.net/returnlist.html">return list</a>'
|
|
|
|
|
timezone = ZoneInfo("America/Chicago")
|
|
|
|
|
returntable="Last Updated<BR> " + str(datetime.datetime.now(timezone))
|
|
|
|
|
returntable+='<br>Click <a href="https://librarynotice.hamik.net">Here</a> to visit the site.'
|
|
|
|
|
returntable += """<form action="https://librarynotice.hamik.net/refresh.php">
|
|
|
|
|
<input type="submit" value="Refresh Items">
|
|
|
|
|
</form>
|
|
|
|
@@ -197,9 +210,30 @@ returntable += """<form action="https://librarynotice.hamik.net/refresh.php">
|
|
|
|
|
td="</td><td>"
|
|
|
|
|
th="</th><th>"
|
|
|
|
|
#returntable = '<a href="https://librarynotice.hamik.net">Click to return to main list</a>'
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Name'+ th +'Count</th></tr>'
|
|
|
|
|
for account in accounts:
|
|
|
|
|
accountcount = sum(b.person == account.name for b in allbooks)
|
|
|
|
|
if accountcount >0:
|
|
|
|
|
returntable += "<tr><td>" + account.name + td + str(accountcount) + "</td></tr>"
|
|
|
|
|
totalcheckedout = len(allbooks)
|
|
|
|
|
returntable += "<tr><td><b>Total" + td + str(totalcheckedout) + "</b></td></tr>" + tableend + "<BR>"
|
|
|
|
|
ills = [d for d in allbooks if (d.isill==True)]
|
|
|
|
|
if len(ills) >=1:
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Type'+ th +'Count</th></tr>'
|
|
|
|
|
for type in mediatypes:
|
|
|
|
|
typecount = sum(b.materialtype == type for b in ills)
|
|
|
|
|
if typecount>0:
|
|
|
|
|
returntable += "<tr><td>" + type + td + str(typecount) + "</td></tr>"
|
|
|
|
|
totalreturnbooks = len(ills)
|
|
|
|
|
returntable += "<tr><td><b>" + "Total" + td + str(totalreturnbooks) + "</b></td></tr>"
|
|
|
|
|
returntable += tableend + "<br>"
|
|
|
|
|
returntable += tablestart + "<colgroup><col/><col/><col/><col/><col/><col/><col/><col/></colgroup><tr><th>Name"+th+"Type"+th+"Times Renewed"+ th + "Renewal Status" + th+"Checked Out"+th+"Due Date"+th+"Title" + th + "ISBN" + th + "Thumbnail</th></tr>"
|
|
|
|
|
for item in ills:
|
|
|
|
|
returntable += "<TR><TD>" + item.person + td + item.materialtype + td + str(item.renewalcount) + td + str(item.renewresult)+ td + str(item.checkoutdate) + td + str(item.duedate) + td + item.title + td + item.isbn + td +'<img src="'+ item.coverurl+'">' +"</td></tr>\n"
|
|
|
|
|
returntable += tableend + "<BR>"
|
|
|
|
|
duesoon = [d for d in allbooks if (d.duedate < datetime.date.today() + datetime.timedelta(days=10)) and not (str(d.renewresult).lower() == 'None'.lower())]
|
|
|
|
|
if len(duesoon) >=1:
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Name'+ th +'Count</th></tr>'
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Type'+ th +'Count</th></tr>'
|
|
|
|
|
for type in mediatypes:
|
|
|
|
|
typecount = sum(b.materialtype == type for b in duesoon)
|
|
|
|
|
if typecount>0:
|
|
|
|
@@ -215,7 +249,7 @@ returnlist = [d for d in allbooks if (d.renewalcount == 3)]
|
|
|
|
|
if len(returnlist) == 0:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Name'+ th +'Count</th></tr>'
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Type'+ th +'Count</th></tr>'
|
|
|
|
|
for type in mediatypes:
|
|
|
|
|
typecount = sum(b.materialtype == type for b in returnlist)
|
|
|
|
|
if typecount>0:
|
|
|
|
@@ -226,11 +260,12 @@ else:
|
|
|
|
|
returntable += tablestart + "<colgroup><col/><col/><col/><col/><col/><col/><col/><col/></colgroup><tr><th>Name"+th+"Type"+th+"Times Renewed"+th+"Checked Out"+th+"Due Date"+th+"Title" + th + "ISBN" + th + "Thumbnail</th></tr>"
|
|
|
|
|
for item in returnlist:
|
|
|
|
|
returntable += "<TR><TD>" + item.person + td + item.materialtype + td + str(item.renewalcount) + td + str(item.checkoutdate) + td + str(item.duedate) + td + item.title + td + item.isbn + td +'<img src="'+ item.coverurl+'">' +"</td></tr>\n"
|
|
|
|
|
returntable += tableend
|
|
|
|
|
returnlist = [d for d in allbooks if (d.renewalcount == 2)]
|
|
|
|
|
if len(returnlist) == 0:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Name'+ th +'Count</th></tr>'
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Type'+ th +'Count</th></tr>'
|
|
|
|
|
for type in mediatypes:
|
|
|
|
|
typecount = sum(b.materialtype == type for b in returnlist)
|
|
|
|
|
if typecount>0:
|
|
|
|
@@ -241,11 +276,12 @@ else:
|
|
|
|
|
returntable += tablestart + "<colgroup><col/><col/><col/><col/><col/><col/><col/><col/></colgroup><tr><th>Name"+th+"Type"+th+"Times Renewed"+th+"Checked Out"+th+"Due Date"+th+"Title" + th + "ISBN" + th + "Thumbnail</th></tr>"
|
|
|
|
|
for item in returnlist:
|
|
|
|
|
returntable += "<TR><TD>" + item.person + td + item.materialtype + td + str(item.renewalcount) + td + str(item.checkoutdate) + td + str(item.duedate) + td + item.title + td + item.isbn + td +'<img src="'+ item.coverurl+'">' +"</td></tr>\n"
|
|
|
|
|
returntable += tableend
|
|
|
|
|
returnlist = [d for d in allbooks if (d.renewalcount == 1)]
|
|
|
|
|
if len(returnlist) == 0:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Name'+ th +'Count</th></tr>'
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Type'+ th +'Count</th></tr>'
|
|
|
|
|
for type in mediatypes:
|
|
|
|
|
typecount = sum(b.materialtype == type for b in returnlist)
|
|
|
|
|
if typecount>0:
|
|
|
|
@@ -256,11 +292,12 @@ else:
|
|
|
|
|
returntable += tablestart + "<colgroup><col/><col/><col/><col/><col/><col/><col/><col/></colgroup><tr><th>Name"+th+"Type"+th+"Times Renewed"+th+"Checked Out"+th+"Due Date"+th+"Title" + th + "ISBN" + th + "Thumbnail</th></tr>"
|
|
|
|
|
for item in returnlist:
|
|
|
|
|
returntable += "<TR><TD>" + item.person + td + item.materialtype + td + str(item.renewalcount) + td + str(item.checkoutdate) + td + str(item.duedate) + td + item.title + td + item.isbn + td +'<img src="'+ item.coverurl+'">' +"</td></tr>\n"
|
|
|
|
|
returntable += tableend
|
|
|
|
|
returnlist = [d for d in allbooks if (d.renewalcount == 0)]
|
|
|
|
|
if len(returnlist) == 0:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Name'+ th +'Count</th></tr>'
|
|
|
|
|
returntable += tablestart + '<colgroup><col/><col/></colgroup><tr><th>Type'+ th +'Count</th></tr>'
|
|
|
|
|
for type in mediatypes:
|
|
|
|
|
typecount = sum(b.materialtype == type for b in returnlist)
|
|
|
|
|
if typecount>0:
|
|
|
|
@@ -271,8 +308,7 @@ else:
|
|
|
|
|
returntable += tablestart + "<colgroup><col/><col/><col/><col/><col/><col/><col/><col/></colgroup><tr><th>Name"+th+"Type"+th+"Times Renewed"+th+"Checked Out"+th+"Due Date"+th+"Title" + th + "ISBN" + th + "Thumbnail</th></tr>"
|
|
|
|
|
for item in returnlist:
|
|
|
|
|
returntable += "<TR><TD>" + item.person + td + item.materialtype + td + str(item.renewalcount) + td + str(item.checkoutdate) + td + str(item.duedate) + td + item.title + td + item.isbn + td +'<img src="'+ item.coverurl+'">' +"</td></tr>\n"
|
|
|
|
|
with open("/var/www/html/returnlist.html","w",encoding='utf-8') as outhtml:
|
|
|
|
|
outhtml.write(returntable)
|
|
|
|
|
returntable += tableend
|
|
|
|
|
htmltable = returntable
|
|
|
|
|
with open("/var/www/html/index.html","w",encoding='utf-8') as outhtml:
|
|
|
|
|
outhtml.write(htmltable)
|
|
|
|
|