aboutsummaryrefslogtreecommitdiff
path: root/libraries/base.py
blob: 3c68616d590041f620fd820d29d28aba05135b6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/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
bgstack15