Skip to content

Commit 20239a0

Browse files
author
Andrew Massey
committed
Update webreader.py
* Added timeout to make program faster * Added a few print statements to make the status more visible.
1 parent 93752e5 commit 20239a0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

webreader.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44

55
def readURL(url):
66
start_time = time.time()
7-
f = urlopen(url)
7+
f = urlopen(url, timeout=3)
88
myfile = f.read()
99
end_time = time.time()
1010
return str(int(round((end_time-start_time)*1000, 0))) + "ms - " + url + "\n"
1111

12+
print("Testing URLs...")
1213
stream = open("sites.yaml", "r")
1314
docs = yaml.load(stream, Loader=yaml.FullLoader)
1415

1516
outputfile = open("outputfile.txt", "w")
1617

1718
for doc in docs['sites']:
19+
print("Testing " + doc)
1820
try:
1921
outputfile.write(readURL(doc))
2022
except:
21-
outputfile.write("Timeout Error on " + doc)
23+
outputfile.write("Timeout Error on " + doc + "\n")
24+
25+
print("Testing Complete.\nResults written to outputfile.txt")

0 commit comments

Comments
 (0)