From a0dd52f3a80c874f65972cabcc6118b1173f6299 Mon Sep 17 00:00:00 2001 From: Ritik Jain Date: Thu, 9 May 2019 19:50:08 +0530 Subject: [PATCH] Travis Build 5 --- pyquotes/pyquotes_test.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/pyquotes/pyquotes_test.py b/pyquotes/pyquotes_test.py index 87f799f..c36b775 100644 --- a/pyquotes/pyquotes_test.py +++ b/pyquotes/pyquotes_test.py @@ -53,18 +53,17 @@ def get_quotes(person, category): count += 1 # Getting the quote of the related author - - get_quote = soup_author.find_all('a', attrs={'title':'view quote'}) - + get_quote = soup_author.find_all('a', attrs={'title': 'view quote'}) quote_list = [] big_list = [] for i in range(count): quote_list.append(get_quote[i].text) big_list.append(quote_list) - if len(quote_list) == 0: + if len(quote_list)==0: return("Oops! It seems that there are no quotes of the author of that category.\nYou may consider changing the category or the author ") quote_list.append(person) + return(quote_list) @@ -77,10 +76,9 @@ def get_quote(person, category): :param category: Category of quote e.g. Motivational :param return: A tuple (quote, author_of_the_quote) """ - quotes = get_quotes(person, category) length = len(quotes) - if(length == 0): # In case no quote of the author exist for that category. + if(length==0): # In case no quote of the author exist for that category. return("No quotes found of that category") else: random_number = random.randint(0, length-1) @@ -90,39 +88,38 @@ def get_quote(person, category): return(tuple(list)) - + def get_quote_of_the_day(): """ This fuction returns quote of the day. :param return: A tuple (quote, author_of_the_quote) """ - URL = "https://www.brainyquote.com/quote_of_the_day" list = [] # Sending a HTTP request to the specified URL and saving the response from server in a response object called response. response = requests.get(URL) - soup = BeautifulSoup(response.content, 'html5lib') a_tags = soup.findAll('img', alt=True) - # Getting all the a tags of the page. + # Getting all the a tags of the page. quote_of_the_day_atag = str(a_tags[0]) + # Grabbing the first a tag of the page + matches=re.findall(r'\"(.+?)\"', quote_of_the_day_atag) - matches=re.findall(r'\"(.+?)\"', quote_of_the_day_atag) # A regular expression which gives a list of all text that is in between quotes. - quote_author_split_list = str(matches[0]).split('-') - # Get a list of quote_of_the_day and the author + # Get a list of quote_of_the_day and the author quote_of_the_day = matches[0].replace(quote_author_split_list[-1], '') quote_of_the_day = quote_of_the_day.replace('-', '') author_name = quote_author_split_list[-1] - # Gives the author_name + # Gives the author_name author_name = author_name.replace(' ', '') + # Removes any extra space list = (quote_of_the_day, author_name)