summaryrefslogtreecommitdiff
path: root/http/index.py
diff options
context:
space:
mode:
Diffstat (limited to 'http/index.py')
-rw-r--r--http/index.py58
1 files changed, 51 insertions, 7 deletions
diff --git a/http/index.py b/http/index.py
index 1628ae2..4699207 100644
--- a/http/index.py
+++ b/http/index.py
@@ -17,15 +17,21 @@ __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)]
- if egg:
+ egg = None
+ for trigger, egg_actions in eggs.iteritems():
+ if cache_path.split('/')[-1].decode('utf-8').lower() == trigger.decode('utf-8'):
+ egg = egg_actions
+ break
+ if egg is not None:
remote_url = urlparse.urljoin(CEZAR_URL,
- '?' + urllib.urlencode({'pid_search': 13650, 'p': 21}))
+ '?' + urllib.urlencode({'pid_search': egg['pid'], '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').replace('ważną licencją', 'gwiazdką'))
+ if egg is not None:
+ if 'replacements' in egg:
+ for replacement in egg['replacements']:
+ content = re.sub(replacement['from'], replacement['to'], content)
open(cache_path, 'w+').write(content)
# returns content of cached file, refreshing cache if necessary
@@ -48,7 +54,7 @@ def handler(req):
else:
break
path = filter(None, re.sub('index\.py$', '', re.sub('^' + BASE_PATH, '', orig_req.uri)).split('/'))
-
+
if path:
# /[ANYTHING]/refresh forces cache refresh
no_cache = len(path) > 1 and path[1] == 'refresh'
@@ -130,10 +136,48 @@ def handler(req):
# credits info
credits_div = bs4('<div style="position:absolute;top:250px;width:130px;left:460px;opacity:0.02">Pomysł Ivana,<br />Ivan jest zajebisty.</div>', 'html.parser', from_encoding='utf-8')
page_content.html.body.div.append(credits_div.div)
-
+
req.content_type = 'text/html'
req.write(page_content.prettify('utf-8'))
else:
req.write('Nothing to see here, move along.')
return apache.OK
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+eggs = {
+ 'wąsłowicz': {
+ 'pid': 13650,
+ 'replacements': [
+ { 'from': re.compile(r'src="\.\./cezar1/fots.*?"'), 'to': 'src="pic/egg.jpg"' },
+ { 'from': 'asłowicz', 'to': 'ąsłowicz' },
+ { 'from': 'ważną licencją', 'to': 'gwiazdką' }
+ ]
+ },
+ 'bubu': {
+ 'pid': 1318
+ }
+}