# HG changeset patch # User Jeff Hammel # Date 1606242802 28800 # Node ID bad7e66f4f2449732cb185bdb1f76af40f3e7d2a # Parent ab37ae0e9cc07d4842f7f47d15b4c41c011cceee py3 diff -r ab37ae0e9cc0 -r bad7e66f4f24 wordstream/api.py --- a/wordstream/api.py Tue Nov 24 08:55:28 2020 -0800 +++ b/wordstream/api.py Tue Nov 24 10:33:22 2020 -0800 @@ -1,4 +1,4 @@ -import urllib2 +from urllib.request import urlopen from random import shuffle class Corpus(dict): @@ -26,7 +26,8 @@ def feed_stuff(self, *args): for arg in args: if arg.startswith('https://') or arg.startswith('http://'): - text = urllib2.urlopen(arg) + with urlopen(arg) as response: + text = response.read() else: text = file(arg).read() self.feed_stream(text)