-
Notifications
You must be signed in to change notification settings - Fork 0
/
Level 6.py
43 lines (34 loc) · 1.25 KB
/
Level 6.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
41
42
43
import re
import zipfile
from collections import defaultdict
SOURCE = r'C:\Users\Tmicha\Downloads\channel\{}.txt'
FILE_SOURCE = '{}.txt'
PATTERN = re.compile('(\d+)', re.MULTILINE | re.DOTALL)
FIRST_NUMBER = '90052'
# NOTE: FIRST NUMBER IS 90052.
# After solving, solve the small riddle to receive this:
# http://www.pythonchallenge.com/pc/def/oxygen.html
def main():
number = FIRST_NUMBER
comments = ''
# Open zip
with zipfile.ZipFile(r'C:\Users\Tmicha\Downloads\channel.zip') as zf:
try:
while True:
filename = FILE_SOURCE.format(number)
with zf.open(filename) as f:
print('Visiting {}...'.format(number))
fullData = f.read().decode('utf-8')
# Get page number
result = PATTERN.search(fullData)
number = result.groups(1)[0]
# Get file comment
info = zf.getinfo(filename)
comments += info.comment.decode('utf-8')
except:
print(comments)
# Print
print('Final URL:')
print(r'http://www.pythonchallenge.com/pc/def/hockey.html')
if __name__ == '__main__':
main()