-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_zipList.py
47 lines (37 loc) · 1015 Bytes
/
6_zipList.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
44
45
46
47
#!/usr/bin/env python
import os
import re
import shutil
import urllib
import zipfile
URL = 'http://www.pythonchallenge.com/pc/def/channel.zip'
ZIPFILE = 'channel.zip'
def solution_1(url):
# download
os.environ['http_proxy'] = 'http://proxy:8888'
urllib.urlretrieve(url, ZIPFILE)
# remove tmp dir
if os.path.exists("resources/lvl6"):
shutil.rmtree('resources/lvl6')
# use tmp dir
os.mkdir("resources/lvl6", 0700)
shutil.move(ZIPFILE, 'resources/lvl6/%s' % ZIPFILE)
# extract
zf = zipfile.ZipFile("resources/lvl6/%s" % ZIPFILE, 'r')
zf.extractall("resources/lvl6")
# seearch for the answer
next_nothing = 90052
while True:
file_data = open('resources/lvl6/%s.txt' % next_nothing, 'r').read()
re_obj = re.search('\d+', file_data)
try:
next_nothing = re_obj.group()
print '.',
except AttributeError:
print "\nERROR: Kein group attribut vorhanden."
print "%s.txt: %s" % (next_nothing, file_data)
break
# cleanup
zf.close()
# shutil.rmtree("tmp")
solution_1(URL)