aboutsummaryrefslogtreecommitdiff
path: root/libraries/base.py
blob: f6f75e4e6caf523fd930766349ceaeaa525f8072 (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
#!/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_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