mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added command to cricket-scores plugin
This commit is contained in:
parent
ffb1359889
commit
dae4244306
@ -3,8 +3,8 @@ import urllib2
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
#score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England"
|
score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England"
|
||||||
score_url = None
|
#score_url = None
|
||||||
|
|
||||||
summary = None
|
summary = None
|
||||||
|
|
||||||
@ -12,25 +12,51 @@ summary = None
|
|||||||
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)
|
||||||
|
prof.register_command("/cricket", 0, 0, "/cricket", "Get latest cricket score.", "Get latest cricket score.", cmd_cricket)
|
||||||
|
|
||||||
def prof_on_start():
|
def prof_on_start():
|
||||||
if score_url:
|
if score_url:
|
||||||
get_scores()
|
get_scores()
|
||||||
|
|
||||||
|
# commands
|
||||||
|
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()
|
||||||
|
|
||||||
# local functions
|
# local functions
|
||||||
def get_scores():
|
def get_scores():
|
||||||
global score_url
|
global score_url
|
||||||
global summary
|
global summary
|
||||||
|
|
||||||
notify = None
|
notify = None
|
||||||
new_summary = None
|
new_summary = None
|
||||||
change = False
|
change = False
|
||||||
|
|
||||||
req = urllib2.Request(score_url, None, {'Content-Type': 'application/json'})
|
result_json = retrieve_scores_json()
|
||||||
f = urllib2.urlopen(req)
|
|
||||||
response = f.read()
|
|
||||||
f.close()
|
|
||||||
result_json = json.loads(response);
|
|
||||||
|
|
||||||
if 'ms' in result_json.keys():
|
if 'ms' in result_json.keys():
|
||||||
new_summary = result_json['ms']
|
new_summary = result_json['ms']
|
||||||
@ -62,3 +88,10 @@ def get_scores():
|
|||||||
prof.cons_show(" " + summary)
|
prof.cons_show(" " + summary)
|
||||||
prof.cons_alert()
|
prof.cons_alert()
|
||||||
prof.notify(notify, 5000, "Cricket score")
|
prof.notify(notify, 5000, "Cricket score")
|
||||||
|
|
||||||
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user