From ae86a12077d1bcb9f1906523d6ebdfdb7aa8bc26 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 10 Feb 2015 23:49:43 +0100 Subject: * I'm way too fucking bored right now --- http/index.py | 9 ++++++++- http/pic/egg.jpg | Bin 0 -> 13851 bytes 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 http/pic/egg.jpg diff --git a/http/index.py b/http/index.py index 9ba0371..4a5dd27 100644 --- a/http/index.py +++ b/http/index.py @@ -17,9 +17,16 @@ __dir__ = os.path.dirname(__file__) # retrieves remote URL content, forwarding browser's UAS def fetch_with_user_agent_spoof(cache_path, remote_url, user_agent): + egg = cache_path.decode('utf-8').lower().endswith('wąsłowicz'.decode('utf-8')) opener = urllib2.build_opener() opener.addheaders = [('User-Agent', user_agent)] - open(cache_path, 'w+').write(opener.open(remote_url).read()) + if egg: + remote_url = urlparse.urljoin(CEZAR_URL, + '?' + urllib.urlencode({'pid_search': 13650, 'p': 21})) + content = opener.open(remote_url).read() + if egg: + content = re.sub(r'src="\.\./cezar1/fots.*?"', 'src="pic/egg.jpg"', content.replace('asłowicz', 'ąsłowicz')) + open(cache_path, 'w+').write(content) # returns content of cached file, refreshing cache if necessary def get_cache_content(cache_key, remote_url, force_refresh=False, user_agent=''): diff --git a/http/pic/egg.jpg b/http/pic/egg.jpg new file mode 100644 index 0000000..1baa065 Binary files /dev/null and b/http/pic/egg.jpg differ -- cgit v1.2.3