summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-10-17 10:54:09 +0200
committeremkael <emkael@tlen.pl>2017-10-17 10:54:09 +0200
commit28324980f4edaa6cf0dcb341a202c52f11f2f050 (patch)
treeaec2ec67ff3e422497f5bf3af346dd20acb2f5be
parent1aef06a04ec087128e67fb7ccbe099131501db6c (diff)
* systematic approach to having fun
-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
+ }
+}