-
Notifications
You must be signed in to change notification settings - Fork 1
/
Python6.py
74 lines (60 loc) · 2 KB
/
Python6.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#Used to make requests
import urllib.request
import re
import os
import zipfile
import sys
r = r'[0-9]*$'
base_url = "http://www.pythonchallenge.com/pc/def/channel.zip"
# Download File
x = urllib.request.urlopen(base_url)
# Open the file, give it a name,
download_file = open("channel.zip", 'bw')
# Read the zip file and write the bytes to the channel.zip file
download_file.write(x.read())
download_file.close()
# Unzip file
# Check if the output directory exists.
if not os.path.exists("output"):
# If not, make it.
os.makedirs("output")
# Open zip file in read mode.
zip_ref = zipfile.ZipFile("channel.zip", 'r')
# Extract zip file
zip_ref.extractall("output")
commentSum = ""
# Open and printout the readme.txt for the user.
readme = open("output/readme.txt", 'r')
print(readme.read())
# Basic interface to either enter first number or exit.
next_nothing = input("Enter file number or 'exit' to quit: ")
if next_nothing == "exit":
print("Goodbye!")
sys.exit()
while next_nothing.isdigit() == True:
# Open file with given number
number_file = open("output/{0}.txt".format(next_nothing), 'r')
# Extract next nothing
# RegEX Mask
r = r'[0-9]*$'
# Converts the number of the current next_nothing to a file name.
curFile = str(next_nothing) + ".txt"
commentSum += zip_ref.getinfo(curFile).comment.decode("utf-8")
previous_nothing = 0
response_nothing = number_file.read()
next_nothing = re.findall(r, response_nothing)[0]
number_file.close()
# Go to next nothing file
if next_nothing.isdigit() != True:
print("STOP! {0}".format(response_nothing))
print("Your last nothing is: {0}".format(previous_nothing))
print("Comments : {0}".format(commentSum))
next_nothing = input("Enter your next nothing or 'exit' to quit: ")
if next_nothing == "exit":
print("Goodbye!")
# break
else:
previous_nothing=next_nothing
print("Next nothing: {0}".format(next_nothing))
#hockey.html
#oxygen.html