diff options
Diffstat (limited to 'http/pic/fetch.py')
-rw-r--r-- | http/pic/fetch.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/http/pic/fetch.py b/http/pic/fetch.py new file mode 100644 index 0000000..0cc3556 --- /dev/null +++ b/http/pic/fetch.py @@ -0,0 +1,27 @@ +# coding=utf-8 + +from mod_python import apache +import os, urllib2 + +CEZAR_URL = 'http://msc.com.pl/cezar' + +def handler(req): + orig_req = req + while True: + if orig_req.prev: + orig_req = orig_req.prev + else: + break + + remote_resource = CEZAR_URL + orig_req.uri + request = urllib2.Request(remote_resource) + request.add_header('User-Agent', orig_req.headers_in['User-Agent']) + file_name = os.path.join(os.path.dirname(__file__), remote_resource.split('/')[-1]) + try: + response = urllib2.urlopen(request) + open(file_name, 'w+').write(response.read()) + req.content_type = response.headers['Content-Type'] + req.write(open(file_name, 'r').read()) + return apache.OK + except urllib2.URLError: + return apache.HTTP_NOT_FOUND |