Skip to content
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
11 changes: 2 additions & 9 deletions pyquotes/powerquotes/powerquotes_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def get_quotes(category):
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 @@ -59,16 +58,10 @@ def get_quote(category):
quotes = get_quotes(category)
length = len(quotes)
if(length == 1):
quote_with_author_list = []
quote_with_author_list.append(quotes[0])
return(tuple(quote_with_author_list))
return(quotes[0])
else:
random_number = random.randint(0, length - 1)
quote_with_author_list = []
quote_with_author_list.append(quotes[random_number])
quote_with_author_list.append(person)

return(tuple(quote_with_author_list))
return(quotes[random_number])


# quotes = get_quotes("power")
Expand Down
6 changes: 4 additions & 2 deletions pyquotes/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ def get_quotes(person: (None, str) = None, category: (None, str) = None):
if person is not None: # person's name is provided
# formatting the name to fit as per URL
Person = "-".join(person.strip().split())
person_link = requests.get(parent_link + "/quotes/authors/" + Person).text
person_link = requests.get(
parent_link + "/quotes/authors/" + Person).text
soup_obj = BeautifulSoup(person_link, "lxml")
for interest in soup_obj.find_all("div", class_="card-body text-center"):
quote = interest.p.find("a", class_="href-noshow").text
tag = interest.p.find("a", class_="category-tag").text
result.append((quote, person))

if category is not None:: # category's name is provided
if category is not None:
# category's name is provided
category_link = requests.get(
parent_link + "/quotes/categories/" + category
).text
Expand Down