Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import urllib.request
import sys
import os
import json
def download(import_file, number_of_files):
f = open(import_file, 'r')
json_data = json.load(f)
images = json_data["images"]
if number_of_files is -1:
number_of_files = len(images)
for i in range(number_of_files):
image_id = images[i]["image_id"]
url = images[i]["url"][0]
print(image_id)
output_name = str(image_id) + ".png"
exist_file = os.path.exists("./" + output_name)
if not exist_file:
try:
urllib.request.urlretrieve(
url, "{0}".format(output_name))
except:
print("failed to download")
pass
if __name__ == "__main__":
import_file = sys.argv[1]
number_of_files = int(sys.argv[2])
download(import_file, number_of_files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment