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 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'http/index.py') 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=''): -- cgit v1.2.3