rest of files, not sorted
This commit is contained in:
66
test/bookgrabbertest.py
Normal file
66
test/bookgrabbertest.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from src.backend.database import Database
|
||||
from src.logic.webrequest import BibTextTransformer, WebRequest
|
||||
|
||||
|
||||
class BookGrabber:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
mode: str = None,
|
||||
data: list = None,
|
||||
app_id: int = None,
|
||||
prof_id: int = None,
|
||||
):
|
||||
self.app_id = app_id
|
||||
self.prof_id = prof_id
|
||||
self.mode = mode
|
||||
self.data = data
|
||||
self.book_id = None
|
||||
|
||||
def run(self):
|
||||
self.db = Database()
|
||||
item = 0
|
||||
for entry in self.data:
|
||||
signature = str(entry)
|
||||
self.logger.log_info("Processing entry: " + signature)
|
||||
|
||||
webdata = WebRequest().get_ppn(entry).get_data()
|
||||
if webdata == "error":
|
||||
continue
|
||||
bd = BibTextTransformer(self.mode).get_data(webdata).return_data()
|
||||
transformer = BibTextTransformer("RDS")
|
||||
rds = transformer.get_data(webdata).return_data("rds_availability")
|
||||
bd.signature = entry
|
||||
# confirm lock is acquired
|
||||
print("lock acquired, adding book to database")
|
||||
self.db.addBookToDatabase(bd, self.app_id, self.prof_id)
|
||||
# get latest book id
|
||||
self.book_id = self.db.getLastBookId()
|
||||
self.logger.log_info("Added book to database")
|
||||
state = 0
|
||||
for rds_item in rds.items:
|
||||
sign = rds_item.superlocation
|
||||
loc = rds_item.location
|
||||
# print(item.location)
|
||||
if self.app_id in sign or self.app_id in loc:
|
||||
state = 1
|
||||
book_id = None
|
||||
# for book in self.books:
|
||||
# if book["bookdata"].signature == entry:
|
||||
# book_id = book["id"]
|
||||
# break
|
||||
self.logger.log_info(f"State of {signature}: {state}")
|
||||
print(
|
||||
"lock acquired, updating availability of "
|
||||
+ str(book_id)
|
||||
+ " to "
|
||||
+ str(state)
|
||||
)
|
||||
try:
|
||||
self.db.setAvailability(self.book_id, state)
|
||||
except sqlite3.OperationalError as e:
|
||||
self.logger.log_error(f"Failed to update availability: {e}")
|
||||
break
|
||||
|
||||
# time.sleep(5)
|
||||
item += 1
|
||||
Reference in New Issue
Block a user