Skip to content

Instantly share code, notes, and snippets.

@jeremyBanks
Created August 7, 2008 06:23
Show Gist options
  • Save jeremyBanks/4353 to your computer and use it in GitHub Desktop.
Save jeremyBanks/4353 to your computer and use it in GitHub Desktop.
[2010-01] script to wait for new LRR postcast episode and download
#!/usr/bin/env python
# encoding: utf-8
import sys, os
import time
try:
import urllib2 as urllib # Python 2.5
except ImportError:
import urllib.request as urllib # Python 3.0
def main():
episode = "aug07"
cooldown = 30 # Time between requests
url = "http://loadingreadyrun.com/media/lrrcasts/%s.mp3" % (episode)
while True:
try:
print("%.1f: Requesting file." % (time.time(),))
request = urllib.urlopen(url)
except urllib.URLError, e:
print("%.1f: Request failed, error code %i." % (time.time(), e.code))
print("%.1f: Retrying in %i seconds." % (time.time(), cooldown))
time.sleep(cooldown)
else:
print("%.1f: Request successful, saving file to desktop." % (time.time(),))
out = open(os.path.expanduser("~/Desktop/%s.mp3" % (episode,)), "w")
out.write(request.read())
print("%.1f: Done.%s" % (time.time(), (chr(7) * 3))) # Beep!
return 0
if __name__ == "__main__": sys.exit(main())
1218091324.6: Requesting file.
1218091324.7: Request failed, error code 404.
1218091324.7: Retrying in 30 seconds.
[...]
1218091541.0: Requesting file.
1218091541.1: Request successful, saving file to desktop.
1218091638.2: Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment