Skip to content

Commit

Permalink
fixed desc
Browse files Browse the repository at this point in the history
  • Loading branch information
HurinHu committed Dec 15, 2021
1 parent e9e9ba7 commit a61cc19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions GoogleNews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def lexical_date_parser(date_to_check):
datetime_tmp=None
date_tmp=copy.copy(date_to_check)
try:
date_tmp = date_tmp[date_tmp.rfind('....')+4:]
date_tmp = date_tmp[date_tmp.rfind('..')+2:]
datetime_tmp=dateparser.parse(date_tmp)
except:
date_tmp = None
Expand Down Expand Up @@ -222,13 +222,13 @@ def get_page(self, page=1):
except Exception:
tmp_media = ''
try:
tmp_date = item.find("div", {"role" : "heading"}).next_sibling.findNext('div').findNext('div').text
tmp_date = item.find("div", {"role" : "heading"}).next_sibling.findNext('div').text
tmp_date,tmp_datetime=lexical_date_parser(tmp_date)
except Exception:
tmp_date = ''
tmp_datetime=None
try:
tmp_desc = item.find("div", {"role" : "heading"}).next_sibling.findNext('div').text.replace("\n","")
tmp_desc = item.find("div", {"role" : "heading"}).next_sibling.text
except Exception:
tmp_desc = ''
try:
Expand Down
10 changes: 8 additions & 2 deletions test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ def testResultNumberAtTwoPages(self):

class TestStringMethods(unittest.TestCase):

def testVersion(self):
googlenews = GoogleNews()
version = '1.6.0'
self.assertIn(version, googlenews.getVersion())
print('Latest version matched')

def testResultContainsKeyword(self):
googlenews = GoogleNews()
googlenews.search(keyword)
result = googlenews.result()[0]
print(result.get('desc').lower())
self.assertIn(keyword.lower(), result.get('desc').lower())
print(result.get('title').lower()+result.get('desc').lower())
self.assertIn(keyword.lower(), result.get('title').lower()+result.get('desc').lower())
print('Result contains keyword')

def testResultHasLink(self):
Expand Down

0 comments on commit a61cc19

Please sign in to comment.