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

Fix wrong returning quotes #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 16 additions & 17 deletions pyquotes/brainyquote/brainyquote.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,23 @@ def get_quotes(person, category):
URL = "https://www.brainyquote.com/authors/" + get_author_link(person)
respone_author = requests.get(URL)
soup_author = BeautifulSoup(respone_author.content, 'html5lib')
categories = soup_author.find_all('div', class_='kw-box')
check = False
count = 0
for i in categories:
a = i.text
replace = a.replace("\n", '')
r = replace.lower()
if category in r:
check = True
count += 1

# Getting the quote of the related author
get_quote = soup_author.find_all('a', attrs={'title': 'view quote'})

# getting div of all quotes on page
all_quotes = list(soup_author.find_all('div',
{'class': [
'm-brick grid-item boxy bqQt qll-new-bg', 'm-brick grid-item boxy bqQt']}
))
quote_list = []
big_list = []
for i in range(count):
quote_list.append((get_quote[i].text, person))
big_list.append(quote_list)
for quote in all_quotes:
# for each quote getting categories and matching them
categories_a_tag = quote.find_all(
'a', {'class': 'qkw-btn btn btn-xs oncl_list_kc'})
for category_a_tag in categories_a_tag:
if((category_a_tag.text).lower() == category.lower()):
# if category matches then get quote and append in quote_list
quote_a_tag = quote.find_all('a', {'title': 'view quote'})
quote_list.append((quote_a_tag[0].text, person))
break

if len(quote_list) == 0:
return('''Oops! It seems that there are no quotes of the author of that
Expand Down