Skip to content

Instantly share code, notes, and snippets.

@hugovk
Created June 29, 2014 16:55
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 hugovk/5890b9ba72060a4d8f4a to your computer and use it in GitHub Desktop.
Save hugovk/5890b9ba72060a4d8f4a to your computer and use it in GitHub Desktop.
Download a file every 30 seconds.
import argparse
import datetime
import os
from twisted.internet import reactor
from twisted.internet import task
# Download an image from a URL every few seconds
parser = argparse.ArgumentParser(
description='Download an image from a URL every few seconds.')
parser.add_argument(
'-u', '--url',
default='http://www.ek.fi/kamera/kamera.jpg',
help='The URL of an image to download')
parser.add_argument(
'-t', '--timeout',
type=int, default=30,
help='Seconds to wait between downloads')
parser.add_argument(
'-o', '--outfile',
default='palace.jpg',
help='The suffix appended to a timestamp for saved files')
args = parser.parse_args()
print "URL: ", args.url
print "Timeout in seconds:", args.timeout
print "Output suffix: ", args.outfile
format = '%Y-%m-%d_%H%M%S'
def do_work():
now = datetime.datetime.today()
print now
timestring = now.strftime(format)
print timestring
outfile = timestring + "_" + args.outfile
print "Fetching " + args.url + " to " + outfile
command = "wget " + args.url + " -O " + outfile
print command
os.system(command)
print "Fetched"
pass
loop = task.LoopingCall(do_work)
loop.start(args.timeout)
reactor.run()
# End of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment