-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge06.py
More file actions
executable file
·61 lines (54 loc) · 1.44 KB
/
challenge06.py
File metadata and controls
executable file
·61 lines (54 loc) · 1.44 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# encoding: utf-8
"""
challenge06.py
http://www.pythonchallenge.com/pc/def/channel.html
zip:
http://www.pythonchallenge.com/pc/def/channel.zip
Started by whimsy on 2010-11-10.
Completed on... 2011-6-25.
Copyright (c) 2010 Will Crawford. All rights reserved.
"""
import sys
import os
import re
import zipfile
def main():
print "Thus begins challenge 6!"
print "The provided hint is:\n"
print "welcome to my zipped list"
print "start from 90052"
print "answer is inside the zip"
print "\n"
the_zip = None
print "Trying ./channel.zip"
try:
the_zip = zipfile.ZipFile('channel.zip', 'r')
except (IOError, RuntimeError):
print "Trying ./challenge06.zip"
try:
the_zip = zipfile.ZipFile('challenge06.zip', 'r')
except (IOError, RuntimeError):
print "Couldn't find zipfile."
return 1
print "File found. \n\nBeginning scan."
pattern = re.compile(r'(\d+)')
next_file = '90052'
next_file = next_file + '.txt'
comments = ''
while next_file:
text = the_zip.read(next_file)
comments += the_zip.getinfo(next_file).comment
next_file = None
print text
try:
next_file = (pattern.search(text)).group(0)
next_file = next_file + '.txt'
except TypeError:
return 1
except AttributeError:
break
text = None
print "\n" + comments
return 0
if __name__ == '__main__': main()