File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # _*_ coding:utf-8 _*
3
+
4
+ """
5
+ @author: Rubén Hortas Astariz <http://rubenhortas.blogspot.com>
6
+ @contact: rubenhortas at gmail.com
7
+ @github: http://github.com/rubenhortas
8
+ @license: CC BY-NC-SA 3.0 <http://creativecommons.org/licenses/by-nc-sa/3.0/>
9
+ @file: 06
10
+ """
11
+
12
+ # http://www.pythonchallenge.com/pc/def/channel.html
13
+
14
+ import signal
15
+ from zipfile import ZipFile
16
+
17
+ from handlers .python import exit_signal_handler
18
+
19
+
20
+ def get_next_file (i , zf , file_name , result ):
21
+ isLast = True
22
+ try :
23
+ file_words = zf .read (file_name ).split ()
24
+ info = zf .getinfo (file_name ).comment
25
+
26
+ result = '{0}{1}' .format (result , info )
27
+
28
+
29
+ for word in file_words :
30
+ if word .isdigit ():
31
+ isLast = False
32
+ next_file = '{0}.txt' .format (word )
33
+ get_next_file (i + 1 , zf , next_file , result )
34
+
35
+ if isLast :
36
+ print result
37
+
38
+ except Exception as e :
39
+ raise e
40
+
41
+ if __name__ == '__main__' :
42
+ signal .signal (signal .SIGINT , exit_signal_handler )
43
+
44
+ result = ''
45
+
46
+ # Download the zip file from http://www.pythonchallenge.com/pc/def/channel.zip
47
+
48
+ try :
49
+ with ZipFile ("channel.zip" ) as zf :
50
+ get_next_file (0 , zf , 'readme.txt' , result )
51
+ except Exception as e :
52
+ print e .message
You can’t perform that action at this time.
0 commit comments