Added error handling to cricket score plugin
This commit is contained in:
@@ -2,8 +2,7 @@ import prof
|
|||||||
import urllib2
|
import urllib2
|
||||||
import json
|
import json
|
||||||
|
|
||||||
#_score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England"
|
_score_url = "http://api.scorescard.com/?type=score&teamone=England&teamtwo=Sri%20Lanka"
|
||||||
_score_url = None
|
|
||||||
_summary = None
|
_summary = None
|
||||||
|
|
||||||
def _cmd_cricket():
|
def _cmd_cricket():
|
||||||
@@ -12,7 +11,7 @@ def _cmd_cricket():
|
|||||||
new_summary = None
|
new_summary = None
|
||||||
|
|
||||||
result_json = _retrieve_scores_json()
|
result_json = _retrieve_scores_json()
|
||||||
|
if (result_json):
|
||||||
if 'ms' in result_json.keys():
|
if 'ms' in result_json.keys():
|
||||||
new_summary = result_json['ms']
|
new_summary = result_json['ms']
|
||||||
|
|
||||||
@@ -44,6 +43,7 @@ def _get_scores():
|
|||||||
|
|
||||||
result_json = _retrieve_scores_json()
|
result_json = _retrieve_scores_json()
|
||||||
|
|
||||||
|
if (result_json):
|
||||||
if 'ms' in result_json.keys():
|
if 'ms' in result_json.keys():
|
||||||
new_summary = result_json['ms']
|
new_summary = result_json['ms']
|
||||||
if new_summary != _summary:
|
if new_summary != _summary:
|
||||||
@@ -77,10 +77,16 @@ def _get_scores():
|
|||||||
|
|
||||||
def _retrieve_scores_json():
|
def _retrieve_scores_json():
|
||||||
req = urllib2.Request(_score_url, None, {'Content-Type': 'application/json'})
|
req = urllib2.Request(_score_url, None, {'Content-Type': 'application/json'})
|
||||||
|
try:
|
||||||
f = urllib2.urlopen(req)
|
f = urllib2.urlopen(req)
|
||||||
|
except:
|
||||||
|
prof.log_info("cricket-score.py: Error getting scores.")
|
||||||
|
return None
|
||||||
|
else:
|
||||||
response = f.read()
|
response = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
return json.loads(response)
|
return json.loads(response)
|
||||||
|
|
||||||
def prof_init(version, status):
|
def prof_init(version, status):
|
||||||
if _score_url:
|
if _score_url:
|
||||||
prof.register_timed(_get_scores, 60)
|
prof.register_timed(_get_scores, 60)
|
||||||
|
|||||||
Reference in New Issue
Block a user