Last Updated: February 25, 2016
·
1.118K
· soasme

Notify webservice

#! -*- coding: utf-8 -*-
# service.py

''' use this, we can make a webservice to support notify from anywhere.

need: web.py, notify-send

usage: python service.py 9123
curl http://youip:9123/notify?title=hello&content=hello-world
'''

import web
import commands

urls = (
    '/notify', 'notify',
)


class notify:
    def GET(self):
        inp = web.input(title='',content='')
        title = inp.title.encode('utf-8')
        content = inp.content.encode('utf-8')
        status, output = commands.getstatusoutput('notify-send "%s" "%s"' % (title, content))
        return ''

if __name__ == '__main__':
    app = web.application(urls, globals())
    app.run()