1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added cons_alert to python API

This commit is contained in:
James Booth 2013-08-04 18:57:33 +01:00
parent 084b03691e
commit 9bbe8def98
3 changed files with 20 additions and 10 deletions

View File

@ -8,7 +8,7 @@ score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=Eng
# hooks # hooks
def prof_init(version, status): def prof_init(version, status):
prof.register_timed(get_scores, 10) prof.register_timed(get_scores, 5)
def get_scores(): def get_scores():
req = urllib2.Request(score_url, None, {'Content-Type': 'application/json'}) req = urllib2.Request(score_url, None, {'Content-Type': 'application/json'})
@ -17,26 +17,35 @@ def get_scores():
f.close() f.close()
result_json = json.loads(response); result_json = json.loads(response);
summary = None summary = None
change = False
if 't1FI' in result_json.keys(): if 't1FI' in result_json.keys():
change = True
summary = result_json['t1FI'] summary = result_json['t1FI']
prof.cons_show(result_json['t1FI']) prof.cons_show(result_json['t1FI'])
if 't2FI' in result_json.keys(): if 't2FI' in result_json.keys():
change = True
summary += "\n" + result_json['t2FI'] summary += "\n" + result_json['t2FI']
prof.cons_show(result_json['t2FI']) prof.cons_show(result_json['t2FI'])
if 't1SI' in result_json.keys(): if 't1SI' in result_json.keys():
change = True
summary += "\n" + result_json['t1SI'] summary += "\n" + result_json['t1SI']
prof.cons_show(result_json['t1SI']) prof.cons_show(result_json['t1SI'])
if 't2SI' in result_json.keys(): if 't2SI' in result_json.keys():
change = True
summary += "\n" + result_json['t2SI'] summary += "\n" + result_json['t2SI']
prof.cons_show(result_json['t2SI']) prof.cons_show(result_json['t2SI'])
if 'ms' in result_json.keys(): if 'ms' in result_json.keys():
change = True
summary += "\n\n" + result_json['ms'] summary += "\n\n" + result_json['ms']
prof.cons_show("") prof.cons_show("")
prof.cons_show(result_json['ms']) prof.cons_show(result_json['ms'])
if change:
prof.cons_alert()
prof.notify(summary, 5000, "Cricket score") prof.notify(summary, 5000, "Cricket score")

View File

@ -6,16 +6,8 @@ import platform
def prof_init(version, status): def prof_init(version, status):
prof.register_command("/platform", 0, 0, "/platform", "Output system information.", "Output system information", cmd_platform) prof.register_command("/platform", 0, 0, "/platform", "Output system information.", "Output system information", cmd_platform)
# local functions # commands
def cmd_platform(): def cmd_platform():
result_summary = platform.platform() result_summary = platform.platform()
# result_machine = plaform.machine()
# result_node = platform,node()
# result_processor = platform.processor()
# result_release = platform.release()
# result_system = platform.system()
# result_version = platform.version()
# prof.cons_show(result_machine + " " + result_node + " " + result_processor + " " + result_release + " " + result_release + " " + result_system + " " + result_version)
prof.cons_show(result_summary) prof.cons_show(result_summary)

View File

@ -28,6 +28,13 @@
#include "ui/notifier.h" #include "ui/notifier.h"
#include "ui/ui.h" #include "ui/ui.h"
static PyObject*
api_cons_alert(PyObject *self, PyObject *args)
{
cons_alert();
return Py_BuildValue("");
}
static PyObject* static PyObject*
api_cons_show(PyObject *self, PyObject *args) api_cons_show(PyObject *self, PyObject *args)
{ {
@ -37,6 +44,7 @@ api_cons_show(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
cons_show("%s", message); cons_show("%s", message);
ui_current_page_off();
return Py_BuildValue(""); return Py_BuildValue("");
} }
@ -111,6 +119,7 @@ api_notify(PyObject *self, PyObject *args)
} }
static PyMethodDef apiMethods[] = { static PyMethodDef apiMethods[] = {
{ "cons_alert", api_cons_alert, METH_NOARGS, "Highlight the console window in the status bar." },
{ "cons_show", api_cons_show, METH_VARARGS, "Print a line to the console." }, { "cons_show", api_cons_show, METH_VARARGS, "Print a line to the console." },
{ "register_command", api_register_command, METH_VARARGS, "Register a command." }, { "register_command", api_register_command, METH_VARARGS, "Register a command." },
{ "register_timed", api_register_timed, METH_VARARGS, "Register a timed function." }, { "register_timed", api_register_timed, METH_VARARGS, "Register a timed function." },