Created
September 19, 2011 21:56
-
-
Save macolyte/1227734 to your computer and use it in GitHub Desktop.
Batch download cover images from Amazon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import shlex, subprocess | |
import os, os.path | |
import sys | |
import time | |
import argparse | |
FILE_NAME = 'amazon.txt' | |
IMAGE_PATH = '~/Documents/BookImages/' | |
def get_images(file_name=FILE_NAME, image_path=IMAGE_PATH): | |
f = open(os.path.expanduser(file_name)) | |
d = os.path.expanduser(image_path) | |
if d[-1] != "/": | |
d += "/" | |
if not os.path.exists(d): | |
os.mkdir(d) | |
os.chdir(d) | |
for line in f: | |
image_URL = "http://images.amazon.com/images/P/%s.01.LZZZZZZZ.jpg" % line.strip() | |
command_line = "curl -O " + image_URL | |
args = shlex.split(command_line) | |
p = subprocess.Popen(args) | |
time.sleep(3) | |
def main(): | |
parser = argparse.ArgumentParser(description="Batch download cover images from Amazon") | |
parser.add_argument('input_file', help="a file with Amazon item IDs, one per line") | |
parser.add_argument('path', help="the path to the folder where the images will be downloaded") | |
args = parser.parse_args() | |
get_images(args.input_file, args.path) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment