Skip to content

Commit

Permalink
Merge pull request #1 from v-goncharenko/dl_enh
Browse files Browse the repository at this point in the history
Enhanced download function
  • Loading branch information
v-goncharenko authored Apr 23, 2022
2 parents 8501d9f + 231f242 commit 34a928d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "somepytools"
version = "1.2.0"
version = "1.2.1"
description = "Just some useful Python tools"
authors = ["Vladilav Goncharenko <[email protected]>"]
maintainers = ["Vladislav Goncharenko <[email protected]>"]
Expand Down
2 changes: 1 addition & 1 deletion somepytools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.2.1"
6 changes: 4 additions & 2 deletions somepytools/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from functools import wraps
from inspect import getfullargspec
from pathlib import Path
from urllib.parse import urlparse
from urllib.request import urlopen
from zipfile import ZipFile

from .constants import SIZE_CONSTANTS
from .typing import Any, Directory, File, get_args
from .typing import Any, Directory, File, Optional, get_args


def str2pathlib(func):
Expand Down Expand Up @@ -75,13 +76,14 @@ def wrapper(*args, **kwargs):


@str2pathlib
def download_url(url: str, save_path: File):
def download_url(url: str, save_path: Optional[File] = None):
"""Downloads and saves data from url
Args:
url: address of file to download
save_path: file path to save to
"""
save_path = save_path or urlparse(url).path.split("/")[-1]
with urlopen(url) as response:
with open(save_path, "wb") as file:
file.write(response.read())
Expand Down

0 comments on commit 34a928d

Please sign in to comment.