Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wikipedia: handle transcluded sections better #2168

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sopel/modules/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,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)
dgw marked this conversation as resolved.
Show resolved Hide resolved

data = get(snippet_url).json()

Expand Down