Skip to content

Instantly share code, notes, and snippets.

@vladkorotnev
Last active October 13, 2015 20:18
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 vladkorotnev/4250876 to your computer and use it in GitHub Desktop.
Save vladkorotnev/4250876 to your computer and use it in GitHub Desktop.
gist 4176162 update for mod_python
from mod_python import apache
from BeautifulSoup import BeautifulSoup
import urllib
import subprocess
import random
import os,sys
import Image
def handler(req):
rooturl = "http://safebooru.org"
url = urllib.urlopen(rooturl+"/index.php?page=post&s=random")
html = url.read()
image = BeautifulSoup(html).findAll('img',id='image')[0]['src']
imgurl = urllib.urlopen(image)
imgdata = imgurl.read()
req.content_type = "image/jpeg"
req.write(imgdata)
return apache.OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment