Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Adding list support, not very elegant, does the job #11

Merged
merged 1 commit into from
Dec 12, 2016
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
29 changes: 29 additions & 0 deletions wikia/wikia.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,35 @@ def section(self, section_title):
if segment['type'] == "paragraph")
return section


def section_lists(self, section_title):
'''
Get the plain text content of a section from `self.sections`.
Returns None if `section_title` isn't found, otherwise returns a whitespace stripped string.

This is a convenience method that wraps self.content.

.. warning:: Calling `section` on a section that has subheadings will NOT return
the full text of all of the subsections. It only gets the text between
`section_title` and the next subheading, which is often empty.
'''
if section_title not in self.sections:
return None

query_params = {
'action': "Articles/AsSimpleJson?/",
'id': self.pageid,
'sub_wikia': self.sub_wikia,
'lang': LANG
}

request = _wiki_request(query_params)
section = [section for section in request['sections'] if section['title'] == section_title][0]
lists = [list['elements'] for list in section['content'] if list['type'] == 'list']
list = [item['text'] for items in lists for item in items]
return list


@cache
def languages():
'''
Expand Down