Added config
This commit is contained in:
@@ -2,6 +2,7 @@ import httpx
|
||||
import datetime
|
||||
import os
|
||||
from pathlib import Path
|
||||
from logger import get_worker_thread_logger
|
||||
from urllib.parse import urlparse
|
||||
|
||||
def get_datestring() -> str:
|
||||
@@ -9,16 +10,17 @@ def get_datestring() -> str:
|
||||
|
||||
|
||||
def cache_cheatsheet(url, outdir: str) -> str | None:
|
||||
|
||||
print("Caching cheatsheet from", url)
|
||||
logger = get_worker_thread_logger()
|
||||
logger.info(f"Caching cheatsheet from {url}")
|
||||
|
||||
try:
|
||||
with httpx.Client() as client:
|
||||
r = client.get(url, timeout=5.0)
|
||||
if not r.is_success and r.headers.get("Content-Type") != "application/pdf":
|
||||
logger.error(f"Failed to fetch URL: {url} (status code: {r.status_code})")
|
||||
return None
|
||||
except httpx.TimeoutException:
|
||||
print("Timeout fetching URL:", url)
|
||||
logger.error(f"Timeout fetching URL: {url}")
|
||||
return None
|
||||
|
||||
data = r.content
|
||||
@@ -33,6 +35,6 @@ def cache_cheatsheet(url, outdir: str) -> str | None:
|
||||
with open(os.path.join(outdir, filesname), "wb") as f:
|
||||
f.write(data)
|
||||
|
||||
print("Saved file to", filesname)
|
||||
logger.info(f"Saved file to {filesname}")
|
||||
|
||||
return filesname
|
||||
|
||||
Reference in New Issue
Block a user