use proper global variable naming

This commit is contained in:
Valentin Boettcher 2024-11-17 11:00:34 -05:00
parent 594058558b
commit 9f5521d307
No known key found for this signature in database
GPG key ID: E034E12B7AF56ACE

View file

@ -15,7 +15,7 @@ from pathlib import Path
from aioimaplib import aioimaplib from aioimaplib import aioimaplib
logger = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
@dataclass @dataclass
@ -62,7 +62,7 @@ def get_download_link(text):
""" """
text = quopri.decodestring(text).decode("utf-8", errors="ignore") text = quopri.decodestring(text).decode("utf-8", errors="ignore")
logger.debug(text) LOGGER.debug(text)
m = re.search(r'''href="(https://.*\.amazon\..*\.pdf.*?)"''', text) m = re.search(r'''href="(https://.*\.amazon\..*\.pdf.*?)"''', text)
if not m: 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]) message_headers = BytesHeaderParser().parsebytes(response.lines[i + 1])
new_max_uid = uid new_max_uid = uid
else: else:
logger.error("error %s" % response) LOGGER.error("error %s" % response)
return new_max_uid, message_headers return new_max_uid, message_headers
@ -150,7 +150,7 @@ async def wait_for_new_message(imap_client, options: Options):
while True: while True:
try: try:
logger.debug("waiting for new message") LOGGER.debug("waiting for new message")
idle_task = await imap_client.idle_start(timeout=float("inf")) idle_task = await imap_client.idle_start(timeout=float("inf"))
msg = await imap_client.wait_server_push() 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()) doc_title = get_document_title(head.as_string())
if doc_title is None: 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 continue
link, page = get_download_link(str(body)) link, page = get_download_link(str(body))
if link is None: if link is None:
logger.info("No pdf download link found.") LOGGER.info("No pdf download link found.")
logger.debug(str(body)) LOGGER.debug(str(body))
continue continue
filename = f"{doc_title.replace(' ','_')}" filename = f"{doc_title.replace(' ','_')}"
@ -191,7 +191,7 @@ async def wait_for_new_message(imap_client, options: Options):
filename += ".pdf" filename += ".pdf"
outpath = options.kindle_dir / filename outpath = options.kindle_dir / filename
logger.info(f"downloading '{doc_title}' -> '{outpath}'") LOGGER.info(f"downloading '{doc_title}' -> '{outpath}'")
urllib.request.urlretrieve(link, outpath) urllib.request.urlretrieve(link, outpath)
shutil.copy(outpath, options.latest_path) shutil.copy(outpath, options.latest_path)
@ -278,15 +278,15 @@ def main():
options = parse_args_and_configure_logging() options = parse_args_and_configure_logging()
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
logger.info("logging in") LOGGER.info("logging in")
try: try:
client = loop.run_until_complete( client = loop.run_until_complete(
make_client(options.server, options.user, options.password, options.mailbox) make_client(options.server, options.user, options.password, options.mailbox)
) )
except Exception as e: 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) exit(1)
logger.info("starting monitor") LOGGER.info("starting monitor")
loop.run_until_complete(wait_for_new_message(client, options)) loop.run_until_complete(wait_for_new_message(client, options))
loop.run_until_complete(client.logout()) loop.run_until_complete(client.logout())