Skip to content

Commit

Permalink
Merge pull request #2168 from sopel-irc/wikipedia-transcluded-sections
Browse files Browse the repository at this point in the history
wikipedia: handle transcluded sections better

Cherry-picked from master: 82e090c
  • Loading branch information
dgw committed Aug 11, 2021
1 parent ae5ba24 commit 64a1e39
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sopel/modules/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,19 @@ def mw_section(server, query, section):
for entry in sections['parse']['sections']:
if entry['anchor'] == section:
section_number = entry['index']
# Needed to handle sections from transcluded pages properly
# e.g. template documentation (usually pulled in from /doc subpage).
# One might expect this prop to be nullable because in most cases it
# will simply repeat the requested page title, but it's always set.
fetch_title = quote(entry['fromtitle'])
break

if not section_number:
return None

snippet_url = ('https://{0}/w/api.php?format=json&redirects'
'&action=parse&page={1}&prop=text'
'&section={2}').format(server, query, section_number)
'&section={2}').format(server, fetch_title, section_number)

data = get(snippet_url).json()

Expand Down

0 comments on commit 64a1e39

Please sign in to comment.