From c061125c628ff06772a9b60009ea051de7c8b8c6 Mon Sep 17 00:00:00 2001 From: rishabhscross Date: Sat, 27 Jul 2019 12:38:05 +0530 Subject: [PATCH 1/3] Fix wrong returning quotes --- pyquotes/brainyquote/brainyquote.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/pyquotes/brainyquote/brainyquote.py b/pyquotes/brainyquote/brainyquote.py index 4ad5698..36de35d 100644 --- a/pyquotes/brainyquote/brainyquote.py +++ b/pyquotes/brainyquote/brainyquote.py @@ -37,24 +37,17 @@ 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'}) + 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: + 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()): + 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 From 17fc7da1a2045a2e874a32bfef16ad11629e8886 Mon Sep 17 00:00:00 2001 From: rishabhscross Date: Sat, 27 Jul 2019 13:20:16 +0530 Subject: [PATCH 2/3] Fix travis errors --- pyquotes/brainyquote/brainyquote.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pyquotes/brainyquote/brainyquote.py b/pyquotes/brainyquote/brainyquote.py index 36de35d..6a94563 100644 --- a/pyquotes/brainyquote/brainyquote.py +++ b/pyquotes/brainyquote/brainyquote.py @@ -37,15 +37,17 @@ 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') - all_quotes = list(soup_author.find_all('div', - {'class': ['m-brick grid-item boxy bqQt qll-new-bg', 'm-brick grid-item boxy bqQt']} - )) + 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 = [] for quote in all_quotes: - categories_a_tag = quote.find_all('a', {'class':'qkw-btn btn btn-xs oncl_list_kc'}) + 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()): - quote_a_tag = quote.find_all('a', {'title':'view quote'}) + quote_a_tag = quote.find_all('a', {'title': 'view quote'}) quote_list.append((quote_a_tag[0].text, person)) break From 4f6e729d673ea5b7aae9f62e3552a960aadd326b Mon Sep 17 00:00:00 2001 From: rishabhscross Date: Sun, 28 Jul 2019 23:07:42 +0530 Subject: [PATCH 3/3] Add comments --- pyquotes/brainyquote/brainyquote.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyquotes/brainyquote/brainyquote.py b/pyquotes/brainyquote/brainyquote.py index 6a94563..a7cb989 100644 --- a/pyquotes/brainyquote/brainyquote.py +++ b/pyquotes/brainyquote/brainyquote.py @@ -37,16 +37,20 @@ 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') + + # 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 = [] 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