#!/usr/bin/env python3 # File: libraries/base.py # Author: bgstack15 # Startdate: 2024-07-06-7 08:08 # SPDX-License-Identifier: GPL-3.0-only # Title: Library Plugin example # Project: library_info # Purpose: base class for library plugins # History: # Usage: # Reference: # Improve: # Dependencies: # dep-devuan: python3-bs4 # For a real library you will need this entry too: #from .base import * import requests, json, dateutil, base64, os from bs4 import BeautifulSoup class BaseLibrary: def __init__(self, username = None, password = None, baseurl = None): self.username = username self.password = password self.baseurl = baseurl # will need cookies or session manager here. def get_reservations(self, verbose = False): sample = { "position": "1", "status": "pending", "date_placed": "2024-07-11", "format": "DVD", "location": "Somewhere", "title": "Example reserved dvd", "img": "DUMMYIMAGE23412341234", "img_type": "image/sample", } return [sample] def get_checkouts(self): """ STUB """ sample = { "title": "sample book 1", "format": "book", "picture": "DUMMYIMAGEprobablybase64ed", "barcode": 912738490172349, "duedate": "2024-07-12", "possible_renewal_date": "2024-07-11", "times_renewed": 0, "checkout_date": "2024-07-02" } return [sample] def get_class_name(self): """ Leave this function as is. It will return the filename. """ return os.path.basename(__file__).replace(".py","") def login(self): """ This is where the login interaction should happen. """ def get_image(self, url): """ Given the url, return the base64-encoded contents and image type as a tuple. """ img_response = self.session.get(url) img_b64 = base64.b64encode(img_response.content).decode() img_type = img_response.headers["Content-Type"] return img_b64, img_type