diff options
author | emkael <emkael@tlen.pl> | 2015-02-10 23:49:43 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2015-02-10 23:49:43 +0100 |
commit | ae86a12077d1bcb9f1906523d6ebdfdb7aa8bc26 (patch) | |
tree | 6ed916bd2129a8ed34f196821d3a84afe86d0065 /http/index.py | |
parent | a756a9525d25622ef5ef8cc909a5605a08b7a205 (diff) |
* I'm way too fucking bored right now
Diffstat (limited to 'http/index.py')
-rw-r--r-- | http/index.py | 9 |
1 files changed, 8 insertions, 1 deletions
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=''): |