-
Notifications
You must be signed in to change notification settings - Fork 0
/
06.py
42 lines (30 loc) · 1.04 KB
/
06.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
#!/usr/bin/env python3
# http://www.pythonchallenge.com/pc/def/channel.html
import signal
from zipfile import ZipFile
from handlers.python import exit_signal_handler
# noinspection PyShadowingNames
def get_next_file(i, zf, file_name, result):
is_last = True
try:
file_words = zf.read(file_name).split()
info = zf.getinfo(file_name).comment
result = f"{result}{info.decode('UTF-8')}"
for word in file_words:
if word.isdigit():
is_last = False
next_file = f"{word.decode('UTF-8')}.txt"
get_next_file(i + 1, zf, next_file, result)
if is_last:
print(result)
except Exception as e:
raise e
if __name__ == '__main__':
signal.signal(signal.SIGINT, exit_signal_handler)
result = ""
# Download the zip file from http://www.pythonchallenge.com/pc/def/channel.zip
try:
with ZipFile('channel.zip') as zf:
get_next_file(0, zf, 'readme.txt', result)
except Exception as e:
print(e)