22import arrow
33import requests
44import arrow
5- import sys
5+ import os
66
77API_BASE_URL = "http://trevor-producer-cdn.api.bbci.co.uk"
88BBC_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
9197class News ():
0 commit comments