Tidied python plugins

Use private naming convention
Move local callback functions to top
This commit is contained in:
James Booth
2013-09-20 00:49:13 +01:00
parent ccf9f7591a
commit 14b5b3ac23
7 changed files with 100 additions and 103 deletions

View File

@@ -2,30 +2,16 @@ import prof
import urllib2
import json
#score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England"
score_url = None
#_score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England"
_score_url = None
_summary = None
summary = None
def prof_init(version, status):
if score_url:
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():
if score_url:
get_scores()
def cmd_cricket():
global score_url
global summary
def _cmd_cricket():
global _score_url
global _summary
new_summary = None
result_json = retrieve_scores_json()
result_json = _retrieve_scores_json()
if 'ms' in result_json.keys():
new_summary = result_json['ms']
@@ -44,23 +30,23 @@ def cmd_cricket():
if 't2SI' in result_json.keys():
prof.cons_show(" " + result_json['t2SI'])
summary = new_summary
_summary = new_summary
prof.cons_show("")
prof.cons_show(" " + summary)
prof.cons_show(" " + _summary)
prof.cons_alert()
def get_scores():
global score_url
global summary
def _get_scores():
global _score_url
global _summary
notify = None
new_summary = None
change = False
result_json = retrieve_scores_json()
result_json = _retrieve_scores_json()
if 'ms' in result_json.keys():
new_summary = result_json['ms']
if new_summary != summary:
if new_summary != _summary:
change = True
if change:
@@ -82,16 +68,28 @@ def get_scores():
notify += "\n" + result_json['t2SI']
prof.cons_show(" " + result_json['t2SI'])
summary = new_summary
notify += "\n\n" + summary
_summary = new_summary
notify += "\n\n" + _summary
prof.cons_show("")
prof.cons_show(" " + summary)
prof.cons_show(" " + _summary)
prof.cons_alert()
prof.notify(notify, 5000, "Cricket score")
def retrieve_scores_json():
req = urllib2.Request(score_url, None, {'Content-Type': 'application/json'})
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)
def prof_init(version, status):
if _score_url:
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():
if _score_url:
_get_scores()