Skip to content

Instantly share code, notes, and snippets.

@mrtazz
Created July 12, 2009 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrtazz/145693 to your computer and use it in GitHub Desktop.
Save mrtazz/145693 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# Python version of picture downloader script
#
import sys
import urllib
# print usage if too less arguments are supplied
APP=sys.argv[0]
USAGE="usage: " + APP + " [staticurl] [.filetype] [first number] [last number]"
if len(sys.argv) != 5:
print USAGE
sys.exit()
URL1=sys.argv[1]
URL2=sys.argv[2]
START=int(sys.argv[3])
END=int(sys.argv[4])
LENGTH=(END - START) + 1
NLENGTH=len(sys.argv[3])
# zeroes are added if string is to short
def addZeroes(number):
if len(str(number)) < NLENGTH:
newNumber=str(0)+str(number)
return addZeroes(newNumber)
else:
return str(number)
for i in range(START, LENGTH+1):
it = addZeroes(i)
FILE=URL1+it+URL2
LOCALFILE=it+URL2
print ("Downloading picture %s of %s (%s)") % (str(i),str(LENGTH),FILE)
urllib.urlretrieve(FILE, LOCALFILE)
print "Finished!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment