From 9f5521d30786aaecf4825ff0c8e2cafcf82f091d Mon Sep 17 00:00:00 2001 From: Valentin Boettcher Date: Sun, 17 Nov 2024 11:00:34 -0500 Subject: [PATCH] use proper global variable naming --- kindle_fetch/kindle_fetch.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/kindle_fetch/kindle_fetch.py b/kindle_fetch/kindle_fetch.py index c8e298d..83b1f8a 100644 --- a/kindle_fetch/kindle_fetch.py +++ b/kindle_fetch/kindle_fetch.py @@ -15,7 +15,7 @@ from pathlib import Path from aioimaplib import aioimaplib -logger = logging.getLogger(__name__) +LOGGER = logging.getLogger(__name__) @dataclass @@ -62,7 +62,7 @@ def get_download_link(text): """ text = quopri.decodestring(text).decode("utf-8", errors="ignore") - logger.debug(text) + LOGGER.debug(text) m = re.search(r'''href="(https://.*\.amazon\..*\.pdf.*?)"''', text) if not m: @@ -121,7 +121,7 @@ async def fetch_messages_headers(imap_client: aioimaplib.IMAP4_SSL, max_uid: int message_headers = BytesHeaderParser().parsebytes(response.lines[i + 1]) new_max_uid = uid else: - logger.error("error %s" % response) + LOGGER.error("error %s" % response) return new_max_uid, message_headers @@ -150,7 +150,7 @@ async def wait_for_new_message(imap_client, options: Options): while True: try: - logger.debug("waiting for new message") + LOGGER.debug("waiting for new message") idle_task = await imap_client.idle_start(timeout=float("inf")) msg = await imap_client.wait_server_push() @@ -173,14 +173,14 @@ async def wait_for_new_message(imap_client, options: Options): doc_title = get_document_title(head.as_string()) if doc_title is None: - logger.info(f"No document title found in '{head.as_string()}'.") + LOGGER.info(f"No document title found in '{head.as_string()}'.") continue link, page = get_download_link(str(body)) if link is None: - logger.info("No pdf download link found.") - logger.debug(str(body)) + LOGGER.info("No pdf download link found.") + LOGGER.debug(str(body)) continue filename = f"{doc_title.replace(' ','_')}" @@ -191,7 +191,7 @@ async def wait_for_new_message(imap_client, options: Options): filename += ".pdf" outpath = options.kindle_dir / filename - logger.info(f"downloading '{doc_title}' -> '{outpath}'") + LOGGER.info(f"downloading '{doc_title}' -> '{outpath}'") urllib.request.urlretrieve(link, outpath) shutil.copy(outpath, options.latest_path) @@ -278,15 +278,15 @@ def main(): options = parse_args_and_configure_logging() loop = asyncio.get_event_loop() - logger.info("logging in") + LOGGER.info("logging in") try: client = loop.run_until_complete( make_client(options.server, options.user, options.password, options.mailbox) ) except Exception as e: - logger.error(f"Failed to connect to the server: {e}") + LOGGER.error(f"Failed to connect to the server: {e}") exit(1) - logger.info("starting monitor") + LOGGER.info("starting monitor") loop.run_until_complete(wait_for_new_message(client, options)) loop.run_until_complete(client.logout())