Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(rss): move RSS reader to its own folder #188

Merged
merged 16 commits into from
Aug 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve(downloader): make sure a parent dirs exist before downloading…
… a file
  • Loading branch information
Guts committed Aug 2, 2024
commit dbde0fbc560df8f04add847760b4a300f8f7732d
12 changes: 10 additions & 2 deletions qtribu/toolbelt/network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# Standard library
import logging
from functools import lru_cache
from typing import Optional
from pathlib import Path
from typing import Optional, Union
from urllib.parse import urlparse, urlunparse

# PyQGIS
Expand Down Expand Up @@ -180,7 +181,7 @@ def get_from_source(
logger.error(err_msg)
self.log(message=err_msg, log_level=2, push=True)

def download_file(self, remote_url: str, local_path: str) -> str:
def download_file_to(self, remote_url: str, local_path: Union[Path, str]) -> str:
"""Download a file from a remote web server accessible through HTTP.

:param remote_url: remote URL
Expand All @@ -190,6 +191,13 @@ def download_file(self, remote_url: str, local_path: str) -> str:
:return: output path
:rtype: str
"""
# check if destination path is a str and if parent folder exists
if isinstance(local_path, Path):
local_path.parent.mkdir(parents=True, exist_ok=True)
local_path = f"{local_path.resolve()}"
elif isinstance(local_path, str):
Path(local_path).parent.mkdir(parents=True, exist_ok=True)

self.log(
message=f"Downloading file from {remote_url} to {local_path}", log_level=4
)
Expand Down