Skip to content

Commit

Permalink
Added direct download to CLI + URL extract
Browse files Browse the repository at this point in the history
  • Loading branch information
bousqi committed Aug 10, 2022
1 parent bfbf29b commit ca29bf3
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/osmad_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,53 @@ def cli(asset_dir, extract_dir,):
osm_assets.load_index(from_cache=True)


@cli.command() # @cli, not @click!
@click.option('--yes', '-y', "yes", is_flag=True, type=bool, help="Do not request for user approval")
@click.option('--url', '-u', "url", is_flag=True, type=bool, help="Do not download, just display url")
@click.option('--filter', '-f', "filters", type=str, required=True, multiple=True, default=None, help="Apply some filters to get only one download")
def get(yes, url, filters):
"""Direct Download of assets based on filters"""
global osm_assets

# feeding assets
osm_assets.load_index(True)

# apply filters
keys = [key for key in osm_assets.keys()]
for one_filter in filters:
keys = [key for key in keys if one_filter.lower() in key.lower()]
dl_list = [osm_assets.get(key) for key in keys]

# display items left
for asset in dl_list:
print(repr(asset))
asset.watchme = True

print(f"> {len(dl_list)} items in the list.\n")
if not len(dl_list):
return

# request user approval to download those item
if not yes:
print("Do you want to proceed with selected items ? [y/N] ", end="")
choice = input().lower()

# abort ?
if choice != "y":
return

# download / urls ?
if not url:
# starting download
dl_list = cli_download(dl_list)
# result
print(f"\nItem(s) downloaded to {AppConfig.DIR_ASSETS}")
else:
# printing URLs
for asset in dl_list:
print(asset.url)
pass

@cli.command() # @cli, not @click!
@click.option('--list', '-l', "wlist", is_flag=True, type=bool, help="List all assets to watch")
@click.option('--clear', '-c', "clear", is_flag=True, type=bool, help="Remove all assets from watch list")
Expand Down

0 comments on commit ca29bf3

Please sign in to comment.