Update pythonbookdef.py
This commit is contained in:
parent
6f79638118
commit
e84da842be
@ -1,8 +1,18 @@
|
||||
class libaccount():
|
||||
import requests
|
||||
import datetime
|
||||
from tabulate import tabulate
|
||||
import boto3
|
||||
import json
|
||||
from json import JSONEncoder
|
||||
|
||||
class libaccount(dict):
|
||||
def __init__(self,name,barcode,pin):
|
||||
dict.__init__(self,name=name, barcode=barcode, pin=pin)
|
||||
self.name=name
|
||||
self.barcode=barcode
|
||||
self.pin=pin
|
||||
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):
|
||||
self.id=itemid
|
||||
@ -37,7 +47,7 @@ class book():
|
||||
print(e.json())
|
||||
finally:
|
||||
pass
|
||||
|
||||
#print(renewresult.json())
|
||||
def sendemail(body,subject):
|
||||
print("Sending Email")
|
||||
boto3.setup_default_session(profile_name='hamik')
|
||||
@ -61,10 +71,29 @@ def sendemail(body,subject):
|
||||
},
|
||||
Source='librarynotices@hamik.net'
|
||||
)
|
||||
upcomingdays=5
|
||||
autorenewaldays=3
|
||||
alwayssendemail=False
|
||||
returndata=False
|
||||
recipients=['dan@hamik.net','allisonmhamik@gmail.com','danalli@hamik.net']
|
||||
uri = "https://auth.na2.iiivega.com/auth/realms/sioux/protocol/openid-connect/token"
|
||||
checkoutsuri='https://sioux.na2.iiivega.com/api/search-result/patrons/me/checkouts'
|
||||
with open('libaccounts.json') as accountfile:
|
||||
accountsjson= json.load(accountfile)
|
||||
|
||||
accounts=[]
|
||||
for account in accountsjson:
|
||||
accounts.append(
|
||||
libaccount(
|
||||
accountsjson[account]['name'],
|
||||
str(accountsjson[account]['barcode']),
|
||||
str(accountsjson[account]['pin']))
|
||||
)
|
||||
|
||||
allbooks=[]
|
||||
mediatypes=[]
|
||||
for myaccount in accounts:
|
||||
account=accounts[myaccount]
|
||||
account=myaccount
|
||||
print(account.name)
|
||||
# Create a session
|
||||
session = requests.Session()
|
||||
@ -123,33 +152,59 @@ for myaccount in accounts:
|
||||
mediatypes.append(thisbook.materialtype)
|
||||
|
||||
allbooks.append(thisbook)
|
||||
duesoon = [d for d in allbooks if d.duedate < datetime.date.today() + datetime.timedelta(days=10)]
|
||||
|
||||
for book in allbooks:
|
||||
#print(datetime.date.today(),book.duedate)
|
||||
if datetime.date.today() > book.duedate:
|
||||
book.renew()
|
||||
|
||||
#sendemail()
|
||||
tablestart="""
|
||||
<!DOCTYPE html PUBLIC "-=//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns=3D"http://www.w3.org/1999/xhtml">
|
||||
<head> </head>
|
||||
<body>
|
||||
<style>
|
||||
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
|
||||
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}
|
||||
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
|
||||
</style><table>"""
|
||||
tableend="</table> </body></html>"
|
||||
|
||||
htmltable="Last Updated" + str(datetime.datetime.now())
|
||||
htmltable+='<br>Click <a href="https://librarynotice.hamik.net">Here</a> to be able to refresh the list.'
|
||||
htmltable += """<form action="https://librarynotice.hamik.net/refresh.php">
|
||||
<input type="submit" value="Refresh Items">
|
||||
</form>
|
||||
"""
|
||||
|
||||
#print(htmltable)
|
||||
td="</td><td>"
|
||||
th="</th><th>"
|
||||
|
||||
duesoon = [d for d in allbooks if d.duedate < datetime.date.today() + datetime.timedelta(days=10)]
|
||||
if len(duesoon) >=1:
|
||||
#print(htmltable)
|
||||
htmltable += tablestart + "<colgroup><col/><col/></colgroup><tr><th>Name"+th+"Count</th></tr>"
|
||||
for type in mediatypes:
|
||||
typecount = sum(b.materialtype == type for b in duesoon)
|
||||
htmltable += "<tr><td>" + type + td + str(typecount) + "</td></tr>"
|
||||
htmltable += "</table><br>" + 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+"Renewal Status" + th + "Title"+ th + "Thumbnail</th></tr>"
|
||||
htmltable += tableend + "<br>" + 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+"Renewal Status" + th + "Title"+ th + "Thumbnail</th></tr>"
|
||||
for item in duesoon:
|
||||
htmltable +="<tr>" + td + item.person + td + item.materialtype + td + str(item.renewalcount) + td + str(item.checkoutdate) + td + str(item.duedate) + td + item.renewresult+ td + item.title + td + '<img src="'+ item.coverurl+'">' +"</td></tr>\n"
|
||||
htmltable += "</table>"
|
||||
htmltable += tableend
|
||||
htmltable += "<br>"
|
||||
htmltable += tablestart + "<colgroup><col/><col/></colgroup><tr><th>Name"+th+"Count</th></tr>"
|
||||
for type in mediatypes:
|
||||
typecount = sum(b.materialtype == type for b in allbooks)
|
||||
htmltable += "<tr><td>" + type + td + str(typecount) + "</td></tr>"
|
||||
htmltable += "</table><br>"
|
||||
htmltable += tableend + "<br>"
|
||||
htmltable += tablestart + "<colgroup><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 + "Thumbnail</th></tr>"
|
||||
for item in allbooks:
|
||||
htmltable += "<TR>"+td + item.person + td + item.materialtype + td + str(item.renewalcount) + td + str(item.checkoutdate) + td + str(item.duedate) + td + item.title + td + '<img src="'+ item.coverurl+'">' +"</td></tr>\n"
|
||||
|
||||
htmltable += "</table>"
|
||||
htmltable += tableend
|
||||
with open("out.html","w",encoding='utf-8') as outhtml:
|
||||
outhtml.write(htmltable)
|
||||
sendemail(htmltable,"Library books due in the next " + str(upcomingdays) + " days " + str(datetime.date.today()))
|
||||
sendemail(htmltable,"Library books due in the next " + str(upcomingdays) + " days " + str(datetime.date.today()))
|
||||
#for item in duesoon:
|
||||
# item.print()
|
Loading…
Reference in New Issue
Block a user