Skip to content

Instantly share code, notes, and snippets.

@vladkorotnev
Created November 30, 2012 14:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladkorotnev/4176162 to your computer and use it in GitHub Desktop.
Save vladkorotnev/4176162 to your computer and use it in GitHub Desktop.
Random Gelbooru grabber
#!/usr/bin/env python
# -- CONFIG ------
isMacQL = 1 # mac quicklook for the lulz
debugLogging = 1 # logs
rootUrls=["http://gelbooru.com","http://vladkorotnev.dyndns.org:8081/art","http://safebooru.org/"]
# ----------------
try:
from BeautifulSoup import BeautifulSoup
except:
print "REQUIRES BEAUTIFULSOUP!"
import urllib
import subprocess
import random
rooturl = rootUrls[random.randint(0,len(rootUrls)-1)]
if debugLogging == 1:
print "gbrandom.py by vladkorotnev"
print "Chosen root url of "+rooturl
url = urllib.urlopen(rooturl+"/index.php?page=post&s=random")
html = url.read()
image = BeautifulSoup(html).findAll('img',id='image')[0]['src']
urllib.urlretrieve(image,'/tmp/gbt.jpg')
if isMacQL == 1:
subprocess.call(["qlmanage","-p","/tmp/gbt.jpg"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment