/usr/share/weechat/python/prowl_notify.py is in weechat-scripts 20180330-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | # Author: kidchunks <me@kidchunks.com>
# Homepage: http://github.com/kidchunks/weechat-prowl-notify
# Version: 3.0
#
# Requires Weechat 0.3.7 or Greater
# Released under the GNU GPL v3
#
# prowl_notify is derived from notifo http://www.weechat.org/files/scripts/notifo.py
# Original Author: ochameau <poirot.alex AT gmail DOT com>
## libraries
import weechat, time, urllib, xml.etree.ElementTree as ET
## registration
weechat.register("prowl_notify", "kidchunks", "3.1", "GPL3", "prowl_notify: Push notifications to iPod Touch, iPhone or iPad with Prowl", "", "")
## settings
API_KEY = '' # API key(s) from Prowl (seperated by commas)
FORCE_ENABLED = False # enables notifications even when not away "True//False"
FLOOD_INTERVAL = 30 # time in seconds between notifications, set to 0 to disable flood control
start_time = time.time() - FLOOD_INTERVAL
## functions
def flood_check():
global start_time
current_time = time.time()
elapsed_time = current_time - start_time
if FLOOD_INTERVAL >= elapsed_time:
return False
else:
start_time = current_time
return True
def post_prowl(label, title, message):
opt_dict = urllib.urlencode({
'apikey': API_KEY,
'application': label,
'event': title,
'description': message
});
weechat.hook_process_hashtable("url:https://api.prowlapp.com/publicapi/add?", { "postfields": opt_dict }, 30 * 1000, "prowl_response", "")
def prowl_response(data, command, rc, stdout, stderr):
# display request response if request failed
if(stderr != ""):
weechat.prnt('', 'prowl_notify plugin: '+stderr+'')
elif "error" in (stdout):
error_msg = ET.fromstring(stdout)
weechat.prnt('', 'prowl_notify plugin: '+error_msg[0].text+'')
return weechat.WEECHAT_RC_OK
def hook_callback(data, bufferp, uber_empty, tagsn, isdisplayed,
ishighlight, prefix, message):
if (bufferp == weechat.current_buffer() and FORCE_ENABLED):
pass
## highlight
elif int(ishighlight) and (weechat.buffer_get_string(bufferp, 'localvar_away') or FORCE_ENABLED):
if flood_check():
buffer = (weechat.buffer_get_string(bufferp, "short_name") or weechat.buffer_get_string(bufferp, "name"))
if prefix == buffer: # treat as pm if user mentions your nick in a pm
post_prowl("WeeChat", "Private Message from " + prefix, message)
elif prefix != buffer: # otherwise, treat as highlight
post_prowl("WeeChat", prefix + " mentioned you on " + buffer, message)
## privmsg
elif weechat.buffer_get_string(bufferp, "localvar_type") == "private" and (weechat.buffer_get_string(bufferp, 'localvar_away') or FORCE_ENABLED):
if flood_check():
post_prowl("WeeChat", "Private Message from " + prefix, message)
return weechat.WEECHAT_RC_OK
# Hooks
weechat.hook_print("", "notify_message", "", 1, "hook_callback", "")
weechat.hook_print("", "notify_private", "", 1, "hook_callback", "")
|