-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge_6.py
50 lines (46 loc) · 1.47 KB
/
challenge_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
44
45
46
47
48
49
50
#!/usr/bin/python
# Python challenge #1: http://www.pythonchallenge.com/pc/def/map.html
# challenge: http://www.pythonchallenge.com/pc/def/channel.html
# Solution: http://www.pythonchallenge.com/pcc/def/oxygen.html
import sys
from sys import stdin
import re ## RexExp
import os
import json
import time
import subprocess
import string
#import urllib
#import urllib2
import pickle
import zipfile
from zipfile import ZipFile
#from StringIO import StringIO
import requests
import io
# Getting zip file automatically
zip_url = "http://www.pythonchallenge.com/pc/def/channel.zip"
#zip_loc = "/mnt/c/Users/arturo/OneDrive/NEW_LIFE/Python/Python Challenge/files/channel.zip"
readme_name = "readme.txt"
reqResponse = requests.get(zip_url)
nothing = "90052"
prev_nothing = ""
pattern = re.compile("Next nothing is ")
comments = []
pairs = []
while True:
with ZipFile(io.BytesIO(reqResponse.content)) as zipFile:
fileName = nothing + ".txt"
myFile = zipFile.open(fileName)
filecontent = myFile.read().decode()
comment = zipFile.getinfo(fileName).comment.decode()
comments.append(comment)
if pattern.search(filecontent):
#pass
nothing = pattern.split(filecontent)[1]
else:
#print ("From",prev_nothing,"to",nothing,":",filecontent,sep=' ')
#print 'From {0} to {1} : {2}'.format(prev_nothing,nothing,filecontent)
#print(''.join(comments))
print ''.join(comments)
sys.exit(0)