Skip to content

Commit

Permalink
Add -u option to list URLs (#947)
Browse files Browse the repository at this point in the history
* Add -u option to list URLs

* Remove newline default
  • Loading branch information
HuidaeCho committed Sep 27, 2023
1 parent ebc612c commit 65f0dd8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/misc/m.download.tnm/m.download.tnm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
# % label: List supported states and exit
# %end
# %flag
# % key: u
# % label: List URLs only without downloading
# %end
# %flag
# % key: f
# % label: List filenames only without downloading
# %end
Expand Down Expand Up @@ -230,6 +234,7 @@ def main():
fs = separator(options["separator"])
list_datasets = flags["d"]
list_states = flags["s"]
list_urls = flags["u"]
list_filenames = flags["f"]
compare_file_size = flags["S"]

Expand Down Expand Up @@ -306,7 +311,7 @@ def main():
for code in sel_codes:
offset = 0
total = None
filenames = []
files = []
while not total or offset < total:
if total:
grass.message(
Expand Down Expand Up @@ -346,13 +351,15 @@ def main():

items = ret["items"]
for item in items:
if list_filenames:
filenames.append(item["downloadURL"].split("/")[-1])
if list_urls:
files.append(item["downloadURL"])
elif list_filenames:
files.append(item["downloadURL"].split("/")[-1])
else:
download_file(item, code, compare_file_size)
offset += len(items)
if filenames:
print(fs.join(filenames))
if files:
print(fs.join(files))


if __name__ == "__main__":
Expand Down

0 comments on commit 65f0dd8

Please sign in to comment.