Skip to content

Commit 3880fb5

Browse files
committed
added change to bbcapi.py
1 parent ad7a81f commit 3880fb5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

bbcli/bbcapi.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import arrow
33
import requests
44
import arrow
5-
import sys
5+
import os
66

77
API_BASE_URL = "http://trevor-producer-cdn.api.bbci.co.uk"
88
BBC_URL = "http://www.bbc.co.uk"
@@ -70,9 +70,12 @@ def get_bbc_story(self):
7070
try:
7171
res = requests.get(API_BASE_URL + "/content/cps/news/front_page", data=None, headers=headers)
7272
except requests.ConnectionError as e:
73-
print "\n" + e.args[0][0]
74-
print 'Reason:', e.args[0][1]
75-
sys.exit()
73+
if hasattr(e, 'reason'):
74+
print 'We failed to reach a server.'
75+
print 'Reason: ', e.reason
76+
elif hasattr(e, 'code'):
77+
print 'The server couldn\'t fulfill the request.'
78+
print 'Error code: ', e.code
7679
return res
7780

7881
def get_bbc_ticker(self):
@@ -83,9 +86,12 @@ def get_bbc_ticker(self):
8386
try:
8487
res = requests.get(BBC_URL + "/news/10284448/ticker.sjson", data=None, headers=ua)
8588
except requests.ConnectionError as e:
86-
print "\n" + e.args[0][0]
87-
print 'Reason:', e.args[0][1]
88-
sys.exit()
89+
if hasattr(e, 'reason'):
90+
print 'We failed to reach a server.'
91+
print 'Reason: ', e.reason
92+
elif hasattr(e, 'code'):
93+
print 'The server couldn\'t fulfill the request.'
94+
print 'Error code: ', e.code
8995
return res
9096

9197
class News():

0 commit comments

Comments
 (0)