Skip to content
Snippets Groups Projects
Commit 1274fefe authored by Tim Neumann's avatar Tim Neumann
Browse files

fix: Fix error handling and clean up

parent 23acd203
No related branches found
No related tags found
1 merge request!11Pad downloader
#!/usr/bin/env python3
from typing import Dict, Optional, Tuple, Generator
from typing import Dict, Optional
from os import environ, path, getcwd, makedirs
from dotenv import load_dotenv
......@@ -37,6 +37,7 @@ def _download_uploaded_file(
r: requests.Response = requests.get(urlunparse(file), headers=headers, cookies=cookies)
if not r.ok:
print(f"Failed to download file {file}. Status: {r.status_code}. Response: {r.content.decode('utf-8')}")
return
file_name = file.path.split("/")[-1]
outfile = outdir + "/uploads/" + file_name
......@@ -72,7 +73,9 @@ def _download_pad_recursive(
r: requests.Response = requests.get(urlunparse(request_url), headers=headers, cookies=cookies)
if not r.ok:
print(f"Failed to download pad {note}. Status: {r.status_code}. Response: {r.content.decode('utf-8')}")
return
if not r.headers["Content-Type"].startswith("text/markdown;"):
print(f"Pad {note} has wrong content type: {r.headers['Content-Type']}.")
return
response_content = r.content
......
#!/usr/bin/env python3
from typing import List, Dict, Optional, Tuple, Iterable
from typing import List, Dict, Optional, Iterable
from jinja2 import Template, StrictUndefined
......@@ -112,10 +112,12 @@ def initPads(files: List[str],
r: requests.Response = requests.post(url_for_this_file, headers=headers, cookies=cookies, data=pad_content.encode('utf-8'), allow_redirects=False)
if not r.ok:
print(f"Failed to create pad for {file_name}. Status: {r.status_code}. Response: {r.content.decode('utf-8')}")
continue
if not r.is_redirect:
print(f"Failed to create pad for {file_name}. Response was not a well formed redirect. Response: {r.content.decode('utf-8')}")
continue
created_page_link = r.next.url
created_page_link: str = r.next.url # type: ignore
all_the_links[file_name] = created_page_link
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment