2013-08-04 11:42:25 -04:00
|
|
|
import prof
|
|
|
|
import urllib2
|
|
|
|
import json
|
|
|
|
|
2013-08-11 17:12:34 -04:00
|
|
|
#score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England"
|
|
|
|
score_url = None
|
2013-08-04 11:42:25 -04:00
|
|
|
|
2013-08-04 14:31:06 -04:00
|
|
|
summary = None
|
|
|
|
|
2013-08-04 13:43:46 -04:00
|
|
|
def prof_init(version, status):
|
2013-08-05 19:28:40 -04:00
|
|
|
if score_url:
|
|
|
|
prof.register_timed(get_scores, 60)
|
2013-08-11 17:19:47 -04:00
|
|
|
prof.register_command("/cricket", 0, 0,
|
|
|
|
"/cricket",
|
|
|
|
"Get latest cricket score.",
|
|
|
|
"Get latest cricket score.",
|
|
|
|
cmd_cricket)
|
2013-08-04 14:31:06 -04:00
|
|
|
|
|
|
|
def prof_on_start():
|
2013-08-05 19:28:40 -04:00
|
|
|
if score_url:
|
|
|
|
get_scores()
|
2013-08-04 13:43:46 -04:00
|
|
|
|
2013-08-11 08:47:54 -04:00
|
|
|
def cmd_cricket():
|
|
|
|
global score_url
|
|
|
|
global summary
|
|
|
|
new_summary = None
|
|
|
|
|
|
|
|
result_json = retrieve_scores_json()
|
|
|
|
|
|
|
|
if 'ms' in result_json.keys():
|
|
|
|
new_summary = result_json['ms']
|
|
|
|
|
|
|
|
prof.cons_show("")
|
|
|
|
prof.cons_show("Cricket score:")
|
|
|
|
if 't1FI' in result_json.keys():
|
|
|
|
prof.cons_show(" " + result_json['t1FI'])
|
|
|
|
|
|
|
|
if 't2FI' in result_json.keys():
|
|
|
|
prof.cons_show(" " + result_json['t2FI'])
|
|
|
|
|
|
|
|
if 't1SI' in result_json.keys():
|
|
|
|
prof.cons_show(" " + result_json['t1SI'])
|
|
|
|
|
|
|
|
if 't2SI' in result_json.keys():
|
|
|
|
prof.cons_show(" " + result_json['t2SI'])
|
|
|
|
|
|
|
|
summary = new_summary
|
|
|
|
prof.cons_show("")
|
|
|
|
prof.cons_show(" " + summary)
|
|
|
|
prof.cons_alert()
|
|
|
|
|
2013-08-04 13:43:46 -04:00
|
|
|
def get_scores():
|
2013-08-04 14:31:06 -04:00
|
|
|
global score_url
|
|
|
|
global summary
|
|
|
|
notify = None
|
|
|
|
new_summary = None
|
2013-08-04 15:58:43 -04:00
|
|
|
change = False
|
2013-08-04 14:31:06 -04:00
|
|
|
|
2013-08-11 08:47:54 -04:00
|
|
|
result_json = retrieve_scores_json()
|
2013-08-04 13:43:46 -04:00
|
|
|
|
2013-08-04 14:31:06 -04:00
|
|
|
if 'ms' in result_json.keys():
|
|
|
|
new_summary = result_json['ms']
|
|
|
|
if new_summary != summary:
|
|
|
|
change = True
|
|
|
|
|
|
|
|
if change:
|
|
|
|
prof.cons_show("")
|
|
|
|
prof.cons_show("Cricket score:")
|
|
|
|
if 't1FI' in result_json.keys():
|
|
|
|
notify = result_json['t1FI']
|
|
|
|
prof.cons_show(" " + result_json['t1FI'])
|
2013-08-04 13:43:46 -04:00
|
|
|
|
2013-08-04 14:31:06 -04:00
|
|
|
if 't2FI' in result_json.keys():
|
|
|
|
notify += "\n" + result_json['t2FI']
|
|
|
|
prof.cons_show(" " + result_json['t2FI'])
|
2013-08-04 13:43:46 -04:00
|
|
|
|
2013-08-04 14:31:06 -04:00
|
|
|
if 't1SI' in result_json.keys():
|
|
|
|
notify += "\n" + result_json['t1SI']
|
|
|
|
prof.cons_show(" " + result_json['t1SI'])
|
2013-08-04 13:43:46 -04:00
|
|
|
|
2013-08-04 14:31:06 -04:00
|
|
|
if 't2SI' in result_json.keys():
|
|
|
|
notify += "\n" + result_json['t2SI']
|
|
|
|
prof.cons_show(" " + result_json['t2SI'])
|
2013-08-04 11:42:25 -04:00
|
|
|
|
2013-08-04 14:31:06 -04:00
|
|
|
summary = new_summary
|
|
|
|
notify += "\n\n" + summary
|
2013-08-04 13:43:46 -04:00
|
|
|
prof.cons_show("")
|
2013-08-04 14:31:06 -04:00
|
|
|
prof.cons_show(" " + summary)
|
2013-08-04 13:57:33 -04:00
|
|
|
prof.cons_alert()
|
2013-08-04 14:31:06 -04:00
|
|
|
prof.notify(notify, 5000, "Cricket score")
|
2013-08-11 08:47:54 -04:00
|
|
|
|
|
|
|
def retrieve_scores_json():
|
|
|
|
req = urllib2.Request(score_url, None, {'Content-Type': 'application/json'})
|
|
|
|
f = urllib2.urlopen(req)
|
|
|
|
response = f.read()
|
|
|
|
f.close()
|
|
|
|
return json.loads(response);
|