Skip to content

Commit

Permalink
Update webreader.py
Browse files Browse the repository at this point in the history
* Added timeout to make program faster
* Added a few print statements to make the status more visible.
  • Loading branch information
Andrew Massey committed Sep 23, 2019
1 parent 93752e5 commit 20239a0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions webreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@

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

print("Testing URLs...")
stream = open("sites.yaml", "r")
docs = yaml.load(stream, Loader=yaml.FullLoader)

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

for doc in docs['sites']:
print("Testing " + doc)
try:
outputfile.write(readURL(doc))
except:
outputfile.write("Timeout Error on " + doc)
outputfile.write("Timeout Error on " + doc + "\n")

print("Testing Complete.\nResults written to outputfile.txt")

0 comments on commit 20239a0

Please sign in to comment.