python-urlopen 0.0.1.2__tar.gz → 0.0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_urlopen-0.0.1.2 → python_urlopen-0.0.1.3}/PKG-INFO +1 -1
- {python_urlopen-0.0.1.2 → python_urlopen-0.0.1.3}/pyproject.toml +5 -1
- {python_urlopen-0.0.1.2 → python_urlopen-0.0.1.3}/urlopen/__main__.py +33 -31
- {python_urlopen-0.0.1.2 → python_urlopen-0.0.1.3}/LICENSE +0 -0
- {python_urlopen-0.0.1.2 → python_urlopen-0.0.1.3}/readme.md +0 -0
- {python_urlopen-0.0.1.2 → python_urlopen-0.0.1.3}/urlopen/__init__.py +0 -0
- {python_urlopen-0.0.1.2 → python_urlopen-0.0.1.3}/urlopen/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "python-urlopen"
|
|
3
|
-
version = "0.0.1.
|
|
3
|
+
version = "0.0.1.3"
|
|
4
4
|
description = "Python urlopen wrapper."
|
|
5
5
|
authors = ["ChenyangGao <wosiwujm@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -30,6 +30,10 @@ python = "^3.10"
|
|
|
30
30
|
http_response = "*"
|
|
31
31
|
python-filewrap = "*"
|
|
32
32
|
|
|
33
|
+
[tool.poetry.scripts]
|
|
34
|
+
python-urlopen = "urlopen.__main__:main"
|
|
35
|
+
urlopen = "urlopen.__main__:main"
|
|
36
|
+
|
|
33
37
|
[build-system]
|
|
34
38
|
requires = ["poetry-core"]
|
|
35
39
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -7,8 +7,8 @@ __doc__ = "python url downloader"
|
|
|
7
7
|
from argparse import ArgumentParser, RawTextHelpFormatter
|
|
8
8
|
|
|
9
9
|
parser = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
|
|
10
|
-
parser.add_argument("
|
|
11
|
-
parser.add_argument("-
|
|
10
|
+
parser.add_argument("url", nargs="?", help="URL to be downloaded")
|
|
11
|
+
parser.add_argument("-o", "--output-file", help="file path to be downloaded, if omitted, print into stdout")
|
|
12
12
|
parser.add_argument("-r", "--resume", action="store_true", help="skip downloaded data")
|
|
13
13
|
parser.add_argument("-hs", "--headers", help="dictionary of HTTP Headers to send with")
|
|
14
14
|
parser.add_argument("-v", "--version", action="store_true", help="print the current version")
|
|
@@ -17,9 +17,11 @@ if args.version:
|
|
|
17
17
|
from urlopen import __version__
|
|
18
18
|
print(".".join(map(str, __version__)))
|
|
19
19
|
raise SystemExit(0)
|
|
20
|
+
url = args.url
|
|
21
|
+
if not url:
|
|
22
|
+
parser.parse_args(["-h"])
|
|
20
23
|
|
|
21
24
|
from collections import deque
|
|
22
|
-
from os import makedirs
|
|
23
25
|
from time import perf_counter
|
|
24
26
|
|
|
25
27
|
from urlopen import download
|
|
@@ -45,35 +47,35 @@ def progress(total=None):
|
|
|
45
47
|
print(f"\r\x1b[K{read_num} | {speed:.2f} MB/s", end="", flush=True)
|
|
46
48
|
dq.append((read_num, cur_t))
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
if not urls:
|
|
50
|
-
from sys import stdin
|
|
51
|
-
urls = (l.removesuffix("\n") for l in stdin)
|
|
52
|
-
savedir = args.savedir
|
|
53
|
-
if savedir:
|
|
54
|
-
makedirs(savedir, exist_ok=True)
|
|
55
|
-
|
|
56
|
-
try:
|
|
50
|
+
def main():
|
|
57
51
|
headers = args.headers
|
|
58
52
|
if headers is not None:
|
|
59
53
|
headers = headers_str_to_dict(headers)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
54
|
+
|
|
55
|
+
output_file = args.output_file
|
|
56
|
+
if output_file:
|
|
57
|
+
from os.path import dirname
|
|
58
|
+
dir_ = dirname(output_file)
|
|
59
|
+
if dir_:
|
|
60
|
+
from os import makedirs
|
|
61
|
+
makedirs(dir_, exist_ok=True)
|
|
62
|
+
|
|
63
|
+
download(
|
|
64
|
+
url,
|
|
65
|
+
output_file,
|
|
66
|
+
resume=args.resume,
|
|
67
|
+
make_reporthook=progress,
|
|
68
|
+
headers=headers,
|
|
69
|
+
)
|
|
70
|
+
else:
|
|
71
|
+
from sys import stdout
|
|
72
|
+
|
|
73
|
+
download(
|
|
74
|
+
url,
|
|
75
|
+
stdout,
|
|
76
|
+
headers=headers,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
if __name__ == "__main__":
|
|
80
|
+
main()
|
|
79
81
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|