Skip to content

Commit

Permalink
Fix /leli on wiki articles that have no paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Oct 1, 2015
1 parent 04cce12 commit b4eca50
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tululbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ def leli(term):
"""

def search_on_wikipedia():
def has_result(page):
return 'Search results' not in page

def parse_content_text(page):
return BeautifulSoup(page).find('div', id='mw-content-text')

def parse_first_paragraph(page):
return parse_content_text(page).find('p').get_text()
return parse_content_text(page).find('p')

def has_result(page):
return ('Search results' not in page and
parse_first_paragraph(page) is not None)

def has_disambiguations(paragraph):
return 'may refer to:' in paragraph
Expand All @@ -62,8 +63,8 @@ def valid_link(tag):
return None

first_paragraph = parse_first_paragraph(page)
if not has_disambiguations(first_paragraph):
return first_paragraph
if not has_disambiguations(first_paragraph.get_text()):
return first_paragraph.get_text()

disambiguation_url = parse_first_disambiguation_link(page)

Expand All @@ -72,7 +73,7 @@ def valid_link(tag):
return None

disambiguated_page = response.text
return parse_first_paragraph(disambiguated_page)
return parse_first_paragraph(disambiguated_page).get_text()

def search_on_google():
query_string = urlencode(dict(q=term))
Expand Down

0 comments on commit b4eca50

Please sign in to comment.