Mercurial > hg > wordstream
changeset 10:bad7e66f4f24
py3
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 24 Nov 2020 10:33:22 -0800 |
parents | ab37ae0e9cc0 |
children | 676ff92e2b1e |
files | wordstream/api.py |
diffstat | 1 files changed, 3 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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)