Download Time Lapse Images in Python -
i want download jpg image refreshed every 15 seconds in web site obtain collection of files can later on assembled time lapse program video. i'm using python ver.3 i'm overwhelmed multitude of suggestions offered, opening , closing of files. isn't there simple command fetch file without opening it, , store index in name?
import urllib.error import urllib.request import time imageurl = 'http://your-web-site.com/imagename.jpg' directoryforimages = '/where/you/want/to/store/image/' imagebasename = 'basename' extension = '.jpg' maxloops = 100 imagenumber in range(0, maxloops): try: # open file object webpage image f = urllib.request.urlopen(imageurl) # open local file store image imagef = open('{0}{1}{2}{3}'.format(directoryforimages, imagebasename, imagenumber, extension), 'wb') # write image local file imagef.write(f.read()) # clean imagef.close() f.close() except urllib.error.httperror: # 'except' block executes if httperror thrown try block, program continues usual. print "image fetch failed. waiting 15 seconds..." time.sleep(15)
Comments
Post a Comment