Skip to content

Commit

Permalink
fixed result()
Browse files Browse the repository at this point in the history
  • Loading branch information
HurinHu committed Nov 14, 2020
1 parent fda7d41 commit 9174eb8
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions GoogleNews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ def set_time_range(self, start, end):

def set_encode(self, encode):
self.__encode = encode

def search(self, key):
"""
Searches for a term in google.com in the news section and retrieves the first page into __results.
Parameters:
key = the search term
"""
Expand Down Expand Up @@ -125,11 +124,13 @@ def get_page(self, page=1):
self.response.close()
except Exception:
pass

def get_news(self, key,deamplify=False):
key = "+".join(key.split(" "))
self.url = 'https://news.google.com/search?q={}+when:{}&hl={}'.format(key,self.__period,self.__lang.lower())


def get_news(self, key="",deamplify=False):
if key != '':
key = "+".join(key.split(" "))
self.url = 'https://news.google.com/search?q={}+when:{}&hl={}'.format(key,self.__period,self.__lang.lower())
else:
self.url = 'https://news.google.com/?hl={}'.format(self.__lang)
try:
self.req = urllib.request.Request(self.url, headers=self.headers)
self.response = urllib.request.urlopen(self.req)
Expand Down Expand Up @@ -161,7 +162,6 @@ def get_news(self, key,deamplify=False):
except:
datetime_obj=None
# link

if deamplify:
try:
link = 'news.google.com/' + article.find("h3").find("a").get("href")
Expand Down Expand Up @@ -200,6 +200,9 @@ def get_news(self, key,deamplify=False):
print(e_parser)
pass

def result(self):
return self.results()

def results(self,sort=False):
"""Returns the __results.
New feature: include datatime and sort the articles in decreasing order"""
Expand Down

0 comments on commit 9174eb8

Please sign in to comment.