mirror of
https://github.com/vale981/kindle_fetch
synced 2025-03-04 08:31:38 -05:00
use proper global variable naming
This commit is contained in:
parent
594058558b
commit
9f5521d307
1 changed files with 11 additions and 11 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Reference in a new issue