aboutsummaryrefslogtreecommitdiff
path: root/library_info_lib.py
blob: ae724ae63722e00eac5e6eaafcb81e1b50198b31 (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
# File: library_info_lib.py
# Author: bgstack15
# Startdate: 2024-07-06-7 08:04
# SPDX-License-Identifier: GPL-3.0-only
# Title: Library for library_info
# Project: library_info
# Purpose: program library that pulls info from book library websites
# History:
# Usage:
# Reference:
# Improve:
#    add library card expiration date
#    add reserved item status
# Dependencies:

import sys, os
import libraries
from config import config

def get_all_configitems(full_images = True, verbose = False):
   # get all checked out items
   checkouts = []
   reservations = []
   for i in config:
      #print(f"Found config entry {i}")
      instance = i["class"](i)
      checkouts += instance.get_checkouts(verbose = verbose)
      reservations += instance.get_reservations(verbose=verbose)
   if not full_images:
      checkouts = trim_full_images(checkouts)
      reservations = trim_full_images(reservations)
   return checkouts, reservations

def get_single_configitem(alias = None, full_images = True, verbose = False):
   checkouts = []
   reservations = []
   this_config = [i for i in config if i["alias"] == alias]
   if not this_config:
      raise Exception(f"Alias not found: {alias}")
   # so now we know we have this_config:
   for i in this_config:
      instance = i["class"](i)
      checkouts += instance.get_checkouts(verbose=verbose)
      reservations += instance.get_reservations(verbose=verbose)
   if not full_images:
      checkouts = trim_full_images(checkouts)
      reservations = trim_full_images(reservations)
   return checkouts, reservations

def trim_full_images(checkouts = []):
   output = []
   for i in checkouts:
      try:
         i.pop("img")
      except:
         pass
      output.append(i)
   return output
bgstack15