Skip to content

Instantly share code, notes, and snippets.

@twolfe18
Created October 21, 2011 03:43
Show Gist options
  • Save twolfe18/1303044 to your computer and use it in GitHub Desktop.
Save twolfe18/1303044 to your computer and use it in GitHub Desktop.
scrape gif.tv's lovely library (use responsibly)
from optparse import OptionParser
import urllib, time, sys, os.path
parser = OptionParser()
parser.add_option('-n', '--howmany', help='how many gifs to download')
parser.add_option('-d', '--delay', help='delay in ms between reqs (default=2000)')
opts,args = parser.parse_args()
howmany = int(opts.howmany) if opts.howmany is not None else 5
delay = int(opts.delay) if opts.delay is not None else 2000
def get_a_gif():
ct = str(int(time.time()))
f = urllib.urlopen('http://www.gif.tv/gifs/get.php?unique=' + ct)
s = f.read();
f.close()
name = s.strip() + '.gif'
if os.path.exists(name): return 'you already have' + name
o = open(name, 'w')
f = urllib.urlopen('http://www.gif.tv/gifs/' + name)
o.write(f.read())
f.close(); o.close()
return '%s (%s KB)' % (name, os.path.getsize(name)/1000)
for i in range(howmany):
print get_a_gif()
time.sleep(delay/1000.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment