I have a code and a question.
import string
import random
import httplib
import urllib
import os
import sys
import inspect
def id_generator(size=5, chars=string.ascii_letters + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
picnumber = raw_input('Please enter the amount of images you want!')
nothingfoundnumber=0
foundnummer=0
scriptpath = os.path.dirname(sys.argv[0])
filename = scriptpath + "/output/"
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
while foundnummer != picnumber:
randompicstring = id_generator()
print "Trying " + str(randompicstring)
try:
urllib.urlretrieve("http://i.imgur.com/" +randompicstring+ ".gif", "/test/" +randompicstring + ".gif")
foundnummer+=1
print str(randompicstring) + "was found! Makes " +str(foundnummer)+ " out of " +str(picnumber)+"!"
except IOError:
nothingfoundnumber+=1
print str(randompicstring) + "not found. It was the "+str(nothingfoundnumber)+" try."
The purpose of this is to try random combinations of asciiletters and numbers to find images on imgur.com (e.g. https://i.stack.imgur.com/onlof.png). If it finds something it should say that and save the image and increase the foundnumber. If it doesn't find an image it should say that and increase the nothingfoundnumber.
Right now it doesn't work, it just says it always finds something and saves nothing. Can someone help me fixing this?