notification via python file on raspberry pi b+
#1
hi
I am running kodi (isengard) on raspberry pi b+.
I managed to associate a script with a keyboard shortcut .
Keyboard shortcut runs a sth.py file which runs an shell script stored in /storage.
I want a notification dialog window to popup every time that sth.py is run .
What should I do ?

Thanks.
Reply
#2
I am not a Linux expert by any means, but if you have the ability to run a python script from within your shell, then it is easy to have that script send a notification to Kodi via json.
Reply
#3
here is my keyboard.xml configured to run py script on specific key combination press
Code:
<keymap>
  <global>
    <keyboard>
      <left mod="ctrl">RunScript(special://masterprofile/keymaps/mountro.py)</left>
      <right mod="ctrl">RunScript(special://masterprofile/keymaps/mountrw.py)</right>
      <left mod="alt">subtitledelayminus</left>
      <right mod="alt">subtitledelayplus</right>
    </keyboard>
  </global>
</keymap>
Here is my python script (mountrw.py) that runs a shell script
Code:
import subprocess


try:
    subprocess.Popen('/storage/rw.sh', shell=True)
except Exception, e:
In old versions of openelec I used to do following to get notifications when the following py got executed
Code:
import subprocess
import xbmcgui

dialog = xbmcgui.Dialog()

try:
    subprocess.Popen('/storage/rw.sh', shell=True)
    dialog.notification('Title', 'some text', xbmcgui.NOTIFICATION_INFO, 5000)
except Exception, e:
Currently I am using open elec 6.0.3 kodi v15.2 (isengard) in which replacing xbmc by kodi does not work .
I tried to give details of my situation.
Thanks.
Reply
#4
Looks like you are on the right track. All you have to do is execute xbmc.GUI.ShowNotification(parameters).
Lookup the above and then you can send a notification of your choice.
Here is some code I use:
PHP Code:
def sendJson(url_in,method,parameters):
        
#
        
results 0
        temp_str 
url_in
        xbmc 
XBMC(temp_str)
        if 
method == notify_method:
                
#xbmc.method(parameters)
                
results xbmc.GUI.ShowNotification(parameters)
                
#title="Library Clean", message = "Initiated")
        
else:
                if 
method == libscan_method:
                        if 
"win" in sys.platform:
                                if 
ip in url_in:
                                        
results xbmc.VideoLibrary.Scan(parameters)
                                else:
                                        
results xbmc.VideoLibrary.Scan()
                        else:
                                
results xbmc.VideoLibrary.Scan()
                else:
                        if 
method == libclean_method:
                                
results xbmc.VideoLibrary.Clean()
        if 
debug_it:
                print 
results
        
return results['result'
Reply
#5
Two ways worked .
(1)long one
enable webserver in settings and write in shell script
Quote:#! /bin/bash
curl -u kodi:kodi -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"'"TITLE"'","message":"'"MESSAGE"'","image":"'"warning"'","displaytime":'"10000"'},"id":1}' http://127.0.0.1:80/jsonrpc
The good thing is you can run shell script in ssh session to verify . Then add its path to py file (like mountrw.py above).
I think running webserver gives extra work to CPU and consumes RAM (even when idle with no user input).

(2)short one
write in py file
Quote:import xbmc
xbmc.executebuiltin('Notification(Hello World,This is a simple example of notifications,5000,/storage/goomba.png)')
I even added a nice icon .
Wish there was a way to show bigger dialog box in center of screen.
Reply
#6
@sumeet 
Is there anyway to automate this:
#! /bin/bash
curl -u kodi:kodi -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"'"TITLE"'","message":"'"MESSAGE"'","image":"'"warning"'","displaytime":'"10000"'},"id":1}' http://127.0.0.1:80/jsonrpc

Like attach it with button and send it to another XBMC?

Thanks
Reply
#7
I made it with python script like this way:
import requests

headers = {
    'Content-Type': 'application/json',
}

data = '{"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"TITLE","message":"MESSAGE","image":"warning","displaytime":10000},"id":1}'

response = requests.post('http://192.168.1.12:8080/jsonrpc', headers=headers, data=data, auth=('kodi', '1234'))


and worked..Can i do it by dialog box instead of notification?..I am going to try and get back to you  Wink

Thanks for all here
Reply

Logout Mark Read Team Forum Stats Members Help
notification via python file on raspberry pi b+0