Skip to content

Commit

Permalink
BUG: Use requests in text example.
Browse files Browse the repository at this point in the history
The text example used Python 3 imports, so did not work on Python 2. But
it also muddled up text/binary data, so did not work on Python 3.
  • Loading branch information
QuLogic committed May 27, 2015
1 parent 413afc9 commit 22c78c6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions examples/text/jugfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import urllib.request, urllib.error, urllib.parse
import requests
from jug import Task
from collections import defaultdict
from time import sleep
Expand All @@ -17,10 +17,13 @@ def get_data(title):
with open(cache, 'rb') as f:
return f.read().decode('utf-8')

title = urllib.parse.quote(title)
url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=' + title
text = urllib.request.urlopen(url).read()
data = json.loads(text)
params = {'action': 'query',
'prop': 'revisions',
'rvprop': 'content',
'format': 'json',
'titles': title}
r = requests.get('http://en.wikipedia.org/w/api.php', params=params)
data = json.loads(r.text)
data = list(data['query']['pages'].values())[0]
text = data['revisions'][0]['*']
text = re.sub(r'(?x) \[ [^]] *? \]\]', '', text)
Expand Down

0 comments on commit 22c78c6

Please sign in to comment.