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

updated testcase update please #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
42 changes: 21 additions & 21 deletions pyquotes/brainyquote/brainyquote.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

def get_author_link(person):
author_name = person.lower()
author_name_split = author_name.split(' ')
author_url_link = ''
author_name_split = author_name.split(" ")
author_url_link = ""
count = 0

for i in author_name_split:
author_url_link += i
count += 1
if count is not len(author_name_split):
author_url_link += '_'
author_url_link += "_"

author_url_link = author_url_link.replace('.', '_')
author_url_link = author_url_link.replace(".", "_")

return author_url_link

Expand All @@ -36,33 +36,33 @@ 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')
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", '')
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'})
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:
return('''Oops! It seems that there are no quotes of the author of that
return """Oops! It seems that there are no quotes of the author of that
category.
\nYou may consider changing the category or the author ''')
\nYou may consider changing the category or the author """
quote_list.append(person)

return(quote_list)
return quote_list


def get_quote(person, category):
Expand All @@ -76,16 +76,16 @@ def get_quote(person, category):
"""
quotes = get_quotes(person, category)
length = len(quotes)
if(length == 0):
if length == 0:
# In case no quote of the author exist for that category.
return("No quotes found of that category")
return "No quotes found of that category"
else:
random_number = random.randint(0, length - 1)
list = []
list.append(quotes[random_number])
list.append(person)

return(tuple(list))
return tuple(list)


def get_quote_of_the_day():
Expand All @@ -99,26 +99,26 @@ def get_quote_of_the_day():
# 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)
soup = BeautifulSoup(response.content, "html5lib")
a_tags = soup.findAll("img", alt=True)

# 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('-')
quote_author_split_list = str(matches[0]).split("-")

# 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('-', '')
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
author_name = author_name.replace(' ', '')
author_name = author_name.replace(" ", "")

# Removes any extra space
return (quote_of_the_day, author_name)
35 changes: 18 additions & 17 deletions pyquotes/powerquotes/powerquotes_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,41 @@ def get_quotes(category):
"""
# Sending a HTTP request and saving the response
# from server in a response object called response.
response = requests.post('http://www.powerquotes.net/search_results.asp',
data={'search_word': category})
soup = BeautifulSoup(response.text, 'lxml')
response = requests.post(
"http://www.powerquotes.net/search_results.asp", data={"search_word": category}
)
soup = BeautifulSoup(response.text, "lxml")
# Grabbing first table in variable table
table = soup.find('table')
table = soup.find("table")

# Grabbing all tables inside table
list_table = table.find_all('table')
list_table = table.find_all("table")

# Grabbing all quotes in variable list1
list1 = list_table[2].find_all('p')
list1 = list_table[2].find_all("p")
quote_list = []
del list1[0]

if len(list1) <= 1:
# In case no quote exis for that category
return('''Oops! It seems that there are no quotes for that
return """Oops! It seems that there are no quotes for that
category.
\nYou may consider changing the category ''')
\nYou may consider changing the category """
else:
for j in range(2):
del list1[len(list1)-1]
del list1[len(list1) - 1]
for i in list1:
a = i.text
replace = a.replace("\'", '')
replace = a.replace("'", "")
replace = replace.replace("\xa0\xa0", " ")
replace = replace.replace("\xa0", " ")
quote_list.append(replace)
quote_list = [k for k in quote_list if k != 'Read complete Powerquote']
quote_list = [k for k in quote_list if k != "Read complete Powerquote"]
main_list = []
t = 0
for h in range(int(len(quote_list)/2)):
main_list.append((quote_list[h+t], quote_list[h+1+t]))
t = t+1
for h in range(int(len(quote_list) / 2)):
main_list.append((quote_list[h + t], quote_list[h + 1 + t]))
t = t + 1

return main_list

Expand All @@ -58,17 +59,17 @@ def get_quote(category):
"""
quotes = get_quotes(category)
length = len(quotes)
if(length == 1):
if length == 1:
list = []
list.append(quotes[0])
return(tuple(list))
return tuple(list)
else:
random_number = random.randint(0, length - 1)
list = []
list.append(quotes[random_number])
list.append(person)

return(tuple(list))
return tuple(list)


# quotes = get_quotes("power")
Expand Down
6 changes: 2 additions & 4 deletions pyquotes/pyquotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
# 2. Get the quote of the day


def get_quotes(person: (None, str) = None,
category: (None, str) = None):
def get_quotes(person: (None, str) = None, category: (None, str) = None):
"""
This function returns all the quotes that matches the input.

Expand All @@ -16,8 +15,7 @@ def get_quotes(person: (None, str) = None,
pass


def get_quote(person: (None, str) = None,
category: (None, str) = None):
def get_quote(person: (None, str) = None, category: (None, str) = None):
"""
This function take a category and a person as a input and returns
a random quote which matches the input.
Expand Down
Loading