def _action(self, action, feed, hostname=None, sleep_time=1): if not hostname: hostname = 'firehoser.superfeedr.com' data = Iq(typ='set', to=hostname, frm=str(self.jid)) child = data.addChild('pubsub', namespace='http://jabber.org/protocol/pubsub') child.addChild(action, {'node': feed, 'jid': str(self.jid)}) self.client.send(data) if sleep_time: time.sleep(sleep_time) self.client.Process(1) self.client.disconnect()
def _action(self, action, feed, hostname=None, sleep_time=1): if not hostname: hostname = 'firehoser.superfeedr.com' data = Iq(typ='set', to=hostname, frm=str(self.jid)) child = data.addChild('pubsub', namespace='http://jabber.org/protocol/pubsub') child.addChild(action, {'node': feed, 'jid': str(self.jid)}) self.client.send(data) if sleep_time: time.sleep(sleep_time) self.client.Process(1) self.client.disconnect()
def send_tune(self, song, debug=False): """Set information about the currently played tune Song is a dictionary with keys: file, title, artist, album, pos, track, length, uri. For details see <http://xmpp.org/protocols/tune/>. """ NS_TUNE = 'http://jabber.org/protocol/tune' iq = Iq(typ='set') iq.setFrom(self.jid) iq.pubsub = iq.addChild('pubsub', namespace=NS_PUBSUB) iq.pubsub.publish = iq.pubsub.addChild('publish', attrs={'node': NS_TUNE}) iq.pubsub.publish.item = iq.pubsub.publish.addChild('item', attrs={'id': 'current'}) tune = iq.pubsub.publish.item.addChild('tune') tune.setNamespace(NS_TUNE) title = None if song.has_key('title'): title = song['title'] elif song.has_key('file'): title = os.path.splitext(os.path.basename(song['file']))[0] if title is not None: tune.addChild('title').addData(title) if song.has_key('artist'): tune.addChild('artist').addData(song['artist']) if song.has_key('album'): tune.addChild('source').addData(song['album']) if song.has_key('pos') and song['pos'] > 0: tune.addChild('track').addData(str(song['pos'])) if song.has_key('time'): tune.addChild('length').addData(str(song['time'])) if song.has_key('uri'): tune.addChild('uri').addData(song['uri']) if debug: self.log.info('Sending tune: %s' % iq.__str__().encode('utf8')) self.conn.send_message(iq)
def send_tune(self, song, debug=False): """Set information about the currently played tune Song is a dictionary with keys: file, title, artist, album, pos, track, length, uri. For details see <http://xmpp.org/protocols/tune/>. """ NS_TUNE = 'http://jabber.org/protocol/tune' iq = Iq(typ='set') iq.setFrom(self.jid) iq.pubsub = iq.addChild('pubsub', namespace=NS_PUBSUB) iq.pubsub.publish = iq.pubsub.addChild('publish', attrs={'node': NS_TUNE}) iq.pubsub.publish.item = iq.pubsub.publish.addChild( 'item', attrs={'id': 'current'}) tune = iq.pubsub.publish.item.addChild('tune') tune.setNamespace(NS_TUNE) title = None if song.has_key('title'): title = song['title'] elif song.has_key('file'): title = os.path.splitext(os.path.basename(song['file']))[0] if title is not None: tune.addChild('title').addData(title) if song.has_key('artist'): tune.addChild('artist').addData(song['artist']) if song.has_key('album'): tune.addChild('source').addData(song['album']) if song.has_key('pos') and song['pos'] > 0: tune.addChild('track').addData(str(song['pos'])) if song.has_key('time'): tune.addChild('length').addData(str(song['time'])) if song.has_key('uri'): tune.addChild('uri').addData(song['uri']) if debug: self.log.info('Sending tune: %s' % iq.__str__().encode('utf8')) self.conn.send_message(iq)
def send_tune(self, song, debug=False): """Set information about the currently played tune Song is a dictionary with keys: file, title, artist, album, pos, track, length, uri. For details see <http://xmpp.org/protocols/tune/>. """ NS_TUNE = "http://jabber.org/protocol/tune" iq = Iq(typ="set") iq.setFrom(self.jid) iq.pubsub = iq.addChild("pubsub", namespace=NS_PUBSUB) iq.pubsub.publish = iq.pubsub.addChild("publish", attrs={"node": NS_TUNE}) iq.pubsub.publish.item = iq.pubsub.publish.addChild("item", attrs={"id": "current"}) tune = iq.pubsub.publish.item.addChild("tune") tune.setNamespace(NS_TUNE) title = None if song.has_key("title"): title = song["title"] elif song.has_key("file"): title = os.path.splitext(os.path.basename(song["file"]))[0] if title is not None: tune.addChild("title").addData(title) if song.has_key("artist"): tune.addChild("artist").addData(song["artist"]) if song.has_key("album"): tune.addChild("source").addData(song["album"]) if song.has_key("pos") and song["pos"] > 0: tune.addChild("track").addData(str(song["pos"])) if song.has_key("time"): tune.addChild("length").addData(str(song["time"])) if song.has_key("uri"): tune.addChild("uri").addData(song["uri"]) if debug: self.log.info("Sending tune: %s" % iq.__str__().encode("utf8")) self.conn.send_message(iq)
def command(self, adhoc_state, vars): """ Send an ad-hoc command. The parameter vars is a list of tupels each defining name, type, and value. So if you pass the following tuple as vars:: [("var-name", "text-single", "example")] ... a field with the following XML will be send:: <field var="var-name" type="text-single"> <value>example</value> </field> The adhoc_state parameter is special to spectrumctl and identifies the command being executed. @param adhoc_state: The command identifier. @type adhoc_state: str @param vars: A list of tuples defining the fields to send. See above for more information. @todo: return str instead of None with the payload of the note stanza in case of a non-error note. @todo: use send_iq instead of doing our own wrapping/casting. @raises RuntimeError: If communicating with the socket fails or the command itself fails. """ from xmpp.simplexml import Node from xmpp.protocol import Iq, NS_DATA, NS_COMMANDS # build adhoc_state field: state_value = Node(tag='value', payload=[adhoc_state]) state = Node(tag='field', payload=[state_value], attrs={ 'type': 'hidden', 'var': 'adhoc_state' }) # build variable fields: fields = [state] for var in vars: name, typ, val = var # build payload for field: var_payload = [] if typ == 'text-multi': for line in val.splitlines(): var_payload.append(Node(tag='value', payload=[line])) else: var_payload.append(Node(tag='value', payload=[val])) # build field stanza: var_node = Node(tag='field', payload=var_payload, attrs={ 'type': typ, 'var': name }) fields.append(var_node) # build x stanza x = Node(tag='x', payload=fields, attrs={ 'xmlns': NS_DATA, 'type': 'submit' }) # build command node cmd_attrs = { 'node': 'transport_admin', 'sessionid': 'WHATEVER', 'xmlns': NS_COMMANDS } cmd = Node(tag='command', attrs=cmd_attrs, payload=[x]) # build IQ node iq = Iq(typ='set', xmlns=None) iq.addChild(node=cmd) answer = self.send_iq(iq) print("Answer: " + str(answer)) cmd = answer.kids[0] if len(cmd.kids) == 0: return note = cmd.kids[0] if note.getAttr('type') == 'error': raise RuntimeError(note.getPayload()[0])
def command( self, adhoc_state, vars ): """ Send an ad-hoc command. The parameter vars is a list of tupels each defining name, type, and value. So if you pass the following tuple as vars:: [("var-name", "text-single", "example")] ... a field with the following XML will be send:: <field var="var-name" type="text-single"> <value>example</value> </field> The adhoc_state parameter is special to spectrumctl and identifies the command being executed. @param adhoc_state: The command identifier. @type adhoc_state: str @param vars: A list of tuples defining the fields to send. See above for more information. @todo: return str instead of None with the payload of the note stanza in case of a non-error note. @todo: use send_iq instead of doing our own wrapping/casting. @raises RuntimeError: If communicating with the socket fails or the command itself fails. """ from xmpp.simplexml import Node from xmpp.protocol import Iq, NS_DATA, NS_COMMANDS # build adhoc_state field: state_value = Node( tag='value', payload=[adhoc_state] ) state = Node( tag='field', payload=[state_value], attrs={'type': 'hidden', 'var': 'adhoc_state'} ) # build variable fields: fields = [state] for var in vars: name, typ, val = var # build payload for field: var_payload = [] if typ == 'text-multi': for line in val.splitlines(): var_payload.append( Node( tag='value', payload=[line] ) ) else: var_payload.append( Node( tag='value', payload=[val] ) ) # build field stanza: var_node = Node( tag='field', payload=var_payload, attrs={'type': typ, 'var': name } ) fields.append( var_node ) # build x stanza x = Node( tag='x', payload=fields, attrs={ 'xmlns': NS_DATA, 'type': 'submit' } ) # build command node cmd_attrs = { 'node': 'transport_admin', 'sessionid': 'WHATEVER', 'xmlns': NS_COMMANDS } cmd = Node( tag='command', attrs=cmd_attrs, payload=[x] ) # build IQ node iq = Iq( typ='set', xmlns=None ) iq.addChild( node=cmd ) answer = self.send_iq( iq ) print( "Answer: " + str(answer) ) cmd = answer.kids[0] if len( cmd.kids ) == 0: return note = cmd.kids[0] if note.getAttr( 'type' ) == 'error': raise RuntimeError( note.getPayload()[0] )