HankHell Posted August 29, 2020 Share Posted August 29, 2020 (edited) anyone know which commands I can use in autoit to download specific files from an api without having to download the entire directory? such as downloading from the THUMBNAILS section under each category; like this (python) expandcollapse popupimport os import requests PRODUCT_URL = 'www.WEBSITE.com' SAVE_DIR = 'THUMBNAILS' def load_products(): return requests.get(PRODUCT_URL).json() def get_objects(products): for product in products: if 'THUMBNAILS' in product and 'url' in product['THUMBNAILS']: yield { 'url': product['THUMBNAILS']['url'], 'name': product['sku'], } def download_objects(objects): try: from tqdm import tqdm except ImportError: tqdm = None if tqdm: for obj in tqdm(objects): download_object(obj) else: for obj in objects: print('Downloading model for {name}'.format(name=obj['name'])) download_object(obj) def download_object(obj): file_name = os.path.join(SAVE_DIR, '{name}.obj'.format(name=obj['name'])) if os.path.isfile(file_name): print('ERROR file already Exists') return r = requests.get(obj['url'], stream=True) with open(file_name, 'wb') as f: for block in r.iter_content(1024): f.write(block) if __name__ == '__main__': try: os.mkdir(SAVE_DIR) except OSError: pass products = load_products() objects = get_objects(products) download_objects(objects) Edited August 29, 2020 by HankHell Link to comment Share on other sites More sharing options...
Danp2 Posted August 29, 2020 Share Posted August 29, 2020 32 minutes ago, HankHell said: anyone know which commands I can use in autoit to download specific files from an api without having to download the entire directory? _INetGetSource to retrieve the raw HTML StringRegExp to parse out the desired links InetGet to download the file HankHell 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
HankHell Posted August 29, 2020 Author Share Posted August 29, 2020 1 hour ago, Danp2 said: _INetGetSource to retrieve the raw HTML StringRegExp to parse out the desired links InetGet to download the file tyvm very helpful Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now