Skip to content

Commit 43675dc

Browse files
Merge pull request #12 from Hemnath-D/master
Handled the exception of empty articles list
2 parents bb28dd2 + 3ab7a96 commit 43675dc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

gnewsclient/gnewsclient.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import requests
33
from bs4 import BeautifulSoup
44
from .utils import editionMap, topicMap, langMap
5-
5+
from .userexception import NotFound
66

77
class gnewsclient:
88

@@ -105,9 +105,9 @@ def set_params(self):
105105

106106
# setting location
107107
if self.location != None:
108-
self.params['geo'] = self.location
109-
# topic overrides location parameter. So, overriding it.
110-
self.params['topic'] = None
108+
self.params['geo'] = self.location
109+
# topic overrides location parameter. So, overriding it.
110+
self.params['topic'] = None
111111

112112
# params setting successful
113113
return True
@@ -140,4 +140,10 @@ def scrape_feed(self, soup):
140140
article['img'] = None
141141
pass
142142
articles.append(article)
143+
try:
144+
if len(articles)==0:
145+
raise NotFound
146+
except NotFound:
147+
print("The articles for the given response are not found")
148+
return
143149
return articles

gnewsclient/userexception.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#User defined exceptions for Gnewsclient
2+
class NotFound(Exception):
3+
"""Raised when the list articles in the function scapefeed() is empty"""
4+
pass

0 commit comments

Comments
 (0)