Enhance logging for missing and soon-to-be-released books in main processing flow
This commit is contained in:
parent
503ffd0930
commit
e0a423f296
1 changed files with 43 additions and 17 deletions
60
main.py
60
main.py
|
|
@ -1,14 +1,9 @@
|
||||||
|
import requests
|
||||||
import connectors
|
import connectors
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
import config
|
import config
|
||||||
|
|
||||||
logging.basicConfig(
|
|
||||||
filename="log",
|
|
||||||
filemode="w",
|
|
||||||
format="%(levelname)s - %(message)s",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Book(dict):
|
class Book(dict):
|
||||||
def __init__(self, asin=""):
|
def __init__(self, asin=""):
|
||||||
|
|
@ -178,14 +173,40 @@ def main():
|
||||||
if len(abs_book_sequence) >= len(audible_book_sequence):
|
if len(abs_book_sequence) >= len(audible_book_sequence):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
logger.info(
|
missing_keys = set(
|
||||||
"%s - %d out of %d",
|
[
|
||||||
series_name,
|
key
|
||||||
len(abs_book_sequence),
|
for key in audible_book_sequence.keys()
|
||||||
len(audible_book_sequence),
|
if key not in abs_book_sequence
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: list missing tomes and show their delivery date if not yet out
|
# Separate missing and soon-to-be-released books
|
||||||
|
missing_books = []
|
||||||
|
soon_to_release_books = []
|
||||||
|
|
||||||
|
for key in missing_keys:
|
||||||
|
try:
|
||||||
|
audnexus.get_book_from_asin(audible_book_sequence[key][0])
|
||||||
|
missing_books.append(key)
|
||||||
|
|
||||||
|
except requests.exceptions.HTTPError:
|
||||||
|
logger.debug("%s Book %d is yet to be released", series_name, key)
|
||||||
|
soon_to_release_books.append(key)
|
||||||
|
|
||||||
|
msgs = []
|
||||||
|
|
||||||
|
if missing_books:
|
||||||
|
msgs.append(f"{len(missing_books)} book.s missing")
|
||||||
|
if soon_to_release_books:
|
||||||
|
msgs.append(f"{len(soon_to_release_books)} book.s yet to be released")
|
||||||
|
|
||||||
|
for i, msg in enumerate(msgs):
|
||||||
|
logger.info(
|
||||||
|
"%s - %s",
|
||||||
|
series_name if i == 0 else "".ljust(len(series_name)),
|
||||||
|
msg,
|
||||||
|
)
|
||||||
|
|
||||||
# TODO: add input to choose which library is to be scaned
|
# TODO: add input to choose which library is to be scaned
|
||||||
break
|
break
|
||||||
|
|
@ -193,11 +214,6 @@ def main():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
logging.getLogger("httpx").setLevel(logging.WARNING)
|
|
||||||
logging.getLogger("audible").setLevel(logging.WARNING)
|
|
||||||
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
|
||||||
logging.getLogger("httpcore").setLevel(logging.WARNING)
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-d", "--dev", action="store_true")
|
parser.add_argument("-d", "--dev", action="store_true")
|
||||||
parser.add_argument("-v", "--verbose", action="store_true")
|
parser.add_argument("-v", "--verbose", action="store_true")
|
||||||
|
|
@ -213,6 +229,16 @@ if __name__ == "__main__":
|
||||||
audible = connectors.AudibleConnector(config.AUDIBLE_AUTH_FILE)
|
audible = connectors.AudibleConnector(config.AUDIBLE_AUTH_FILE)
|
||||||
audnexus = connectors.AudNexusConnector()
|
audnexus = connectors.AudNexusConnector()
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
filename="log",
|
||||||
|
filemode="w",
|
||||||
|
format="%(levelname)s - %(message)s" if args.verbose else "%(message)s",
|
||||||
|
)
|
||||||
|
logging.getLogger("httpx").setLevel(logging.WARNING)
|
||||||
|
logging.getLogger("audible").setLevel(logging.WARNING)
|
||||||
|
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||||
|
logging.getLogger("httpcore").setLevel(logging.WARNING)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.setLevel(logging.DEBUG if args.verbose else logging.INFO)
|
logger.setLevel(logging.DEBUG if args.verbose else logging.INFO)
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue