openlp/scripts/openlp-remoteclient.py

71 lines
3.3 KiB
Python
Raw Normal View History

2009-08-10 18:20:46 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
2009-10-30 01:26:45 +00:00
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2012-12-30 19:41:24 +00:00
# Copyright (c) 2008-2013 Raoul Snyman #
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
2012-11-07 21:37:01 +00:00
# Frode Woldsund, Martin Zibricky #
2009-10-30 01:26:45 +00:00
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2009-08-10 18:20:46 +00:00
import urllib
2009-08-12 16:29:00 +00:00
import sys
from optparse import OptionParser
def sendData(options):
addr = 'http://%s:%s/send/%s?q=%s' % (options.address, options.port,
options.event, options.message)
2009-08-12 16:29:00 +00:00
try:
urllib.urlopen(addr)
print u'Message sent ', addr
2009-08-12 16:29:00 +00:00
except:
print u'Error thrown ', sys.exc_info()[1]
2009-08-12 16:29:00 +00:00
def main():
usage = "usage: %prog [-a address] [-p port] [-e event] [-m message]"
2009-08-12 16:29:00 +00:00
parser = OptionParser(usage=usage)
2010-02-03 18:53:31 +00:00
parser.add_option("-p", "--port", default=4316,
2009-08-12 16:29:00 +00:00
help="IP Port number %default ")
parser.add_option("-a", "--address",
help="Recipient address ",
default="localhost")
parser.add_option("-e", "--event",
2010-12-13 14:24:16 +00:00
help="Action to be performed",
default="alerts_text")
2009-08-12 16:29:00 +00:00
parser.add_option("-m", "--message",
help="Message to be passed for the action",
default="")
2009-08-10 18:20:46 +00:00
2009-08-12 16:29:00 +00:00
(options, args) = parser.parse_args()
2010-03-09 19:43:11 +00:00
if args:
2009-08-12 16:29:00 +00:00
parser.print_help()
parser.error("incorrect number of arguments")
elif options.address is None:
parser.print_help()
parser.error("IP address missing")
else:
sendData(options)
2009-08-10 18:20:46 +00:00
if __name__ == u'__main__':
2010-07-27 09:32:52 +00:00
main()