-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_23.py
40 lines (32 loc) · 1.05 KB
/
level_23.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/env python
# coding=utf-8
# http://butter:fly@www.pythonchallenge.com/pc/hex/bonus.html
# The 'this' module.
import codecs
import re
import sys
from io import StringIO
import requests
PREFIX = "http://butter:fly@www.pythonchallenge.com/pc/hex/"
url = PREFIX + 'bonus.html'
def catch(text, pattern=r'<!--(.*?)-->', cnt=0):
return re.findall(pattern, text, re.DOTALL)[cnt]
def solve(something):
capture = StringIO()
save_stdout, sys.stdout = sys.stdout, capture
import this
sys.stdout = save_stdout
guts = capture.getvalue().lower()
message = codecs.encode(something,"rot13").strip('\n\'')
# in the face of what?
searchfor = " ".join(message.split()[:-1])
# in the face
m = re.search(searchfor + r" (\w+)", guts)
return m.group(1)
if __name__ == "__main__":
r = requests.get(url)
something = catch(r.text, cnt=2)
answer = solve(something)
# ambiguity
print(PREFIX + answer + '.html')
# http://butter:fly@www.pythonchallenge.com/pc/hex/ambiguity.html