Last active
October 13, 2015 20:18
-
-
Save vladkorotnev/4250876 to your computer and use it in GitHub Desktop.
gist 4176162 update for mod_python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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