Skip to content

Commit 78e4a32

Browse files
authored
Release 8.0.4
Merge pull request #2704 from sopel-irc/release-prep/8.0.4
2 parents 0942acd + a8376dd commit 78e4a32

4 files changed

Lines changed: 36 additions & 9 deletions

File tree

NEWS

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ This file is used to auto-generate the "Changelog" section of Sopel's website.
22
When adding new entries, follow the style guide in NEWS.spec.md to avoid
33
causing problems with the site build.
44

5+
Changes between 8.0.3 and 8.0.4
6+
===============================
7+
8+
Plugin changes
9+
--------------
10+
11+
* wikipedia:
12+
* Comply with Wikimedia Foundation user-agent policy [[#2702][]]
13+
* wiktionary:
14+
* Comply with Wikimedia Foundation user-agent policy [[#2702][]]
15+
16+
[#2702]: https://github.com/sopel-irc/sopel/pull/2702
17+
18+
519
Changes between 8.0.2 and 8.0.3
620
===============================
721

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespaces = false
1111

1212
[project]
1313
name = "sopel"
14-
version = "8.0.3"
14+
version = "8.0.4"
1515
description = "Simple and extensible IRC bot"
1616
maintainers = [
1717
{ name="dgw" },

sopel/builtins/wikipedia.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,19 @@
1414

1515
from requests import get
1616

17-
from sopel import plugin
17+
from sopel import __version__ as sopel_version, plugin
1818
from sopel.config import types
1919

2020

2121
LOGGER = logging.getLogger(__name__)
2222

2323
REDIRECT = re.compile(r'^REDIRECT (.*)')
2424
PLUGIN_OUTPUT_PREFIX = '[wikipedia] '
25+
PLUGIN_USER_AGENT = 'sopel-wikipedia/{version} (https://sopel.chat/)'.format(
26+
version=sopel_version)
27+
WIKI_REQUEST_HEADERS = {
28+
'User-Agent': PLUGIN_USER_AGENT,
29+
}
2530

2631

2732
class WikiParser(HTMLParser):
@@ -169,7 +174,7 @@ def mw_search(server, query, num):
169174
'&list=search&srlimit=%d&srprop=timestamp&srwhat=text'
170175
'&srsearch=') % (server, num)
171176
search_url += query
172-
query = get(search_url).json()
177+
query = get(search_url, headers=WIKI_REQUEST_HEADERS).json()
173178
if 'query' in query:
174179
query = query['query']['search']
175180
return [r['title'] for r in query]
@@ -213,7 +218,7 @@ def mw_snippet(server, query):
213218
'&action=query&prop=extracts&exintro&explaintext'
214219
'&exchars=500&redirects&titles=')
215220
snippet_url += query
216-
snippet = get(snippet_url).json()
221+
snippet = get(snippet_url, headers=WIKI_REQUEST_HEADERS).json()
217222
snippet = snippet['query']['pages']
218223

219224
# For some reason, the API gives the page *number* as the key, so we just
@@ -244,7 +249,7 @@ def mw_section(server, query, section):
244249
sections_url = ('https://{0}/w/api.php?format=json&redirects'
245250
'&action=parse&prop=sections&page={1}'
246251
.format(server, query))
247-
sections = get(sections_url).json()
252+
sections = get(sections_url, headers=WIKI_REQUEST_HEADERS).json()
248253

249254
fetch_title = section_number = None
250255

@@ -265,7 +270,7 @@ def mw_section(server, query, section):
265270
'&action=parse&page={1}&prop=text'
266271
'&section={2}').format(server, quote(fetch_title), section_number)
267272

268-
data = get(snippet_url).json()
273+
data = get(snippet_url, headers=WIKI_REQUEST_HEADERS).json()
269274

270275
parser = WikiParser(section.replace('_', ' '))
271276
parser.feed(data['parse']['text']['*'])
@@ -296,7 +301,7 @@ def mw_image_description(server, image):
296301
])
297302
url = "https://{server}/w/api.php?{params}".format(server=server, params=params)
298303

299-
response = get(url)
304+
response = get(url, headers=WIKI_REQUEST_HEADERS)
300305
json = response.json()
301306

302307
try:

sopel/builtins/wiktionary.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111

1212
import requests
1313

14-
from sopel import plugin
14+
from sopel import __version__ as sopel_version, plugin
1515
from sopel.tools import web
1616

1717
PLUGIN_OUTPUT_PREFIX = '[wiktionary] '
18+
PLUGIN_USER_AGENT = 'sopel-wiktionary/{version} (https://sopel.chat/)'.format(
19+
version=sopel_version)
20+
WIKI_REQUEST_HEADERS = {
21+
'User-Agent': PLUGIN_USER_AGENT,
22+
}
1823

1924
uri = 'https://en.wiktionary.org/w/index.php?title=%s&printable=yes'
2025
r_sup = re.compile(r'<sup[^>]+>.+?</sup>') # Superscripts that are references only, not ordinal indicators, etc...
@@ -53,7 +58,10 @@ def text(html):
5358

5459

5560
def wikt(word):
56-
bytes = requests.get(uri % web.quote(word)).text
61+
bytes = requests.get(
62+
uri % web.quote(word),
63+
headers=WIKI_REQUEST_HEADERS,
64+
).text
5765
bytes = r_ul.sub('', bytes)
5866

5967
mode = None

0 commit comments

Comments
 (0)