pubsubclient: e73c503e48d028e22074fb624d1bc4fca46e7f8b
1: #!/usr/bin/env python
2: import xmpp
3: import sys
4: import os
5: import time
6: from pubsubclient import PubSubClient, Node, Server, JID
7: import simplexml
8: import lxml.etree as etree
9: from random import Random
10: import string
11: from lxml.etree import ElementTree, Element, SubElement
12: import pygtk
13: import gtk
14: import gobject
15: import feedparser
16: from StringIO import StringIO
17: from kiwi.ui.objectlist import Column, ObjectTree, ObjectList
18:
19: class Writer:
20:
21: def __init__(self, node):
22: """Make a Writer object, which is the application. A Writer
23: contains an application window and a PubSubClient."""
24: # This is the JID to use. Currently hard-coded
25: self.client = PubSubClient("test1@localhost", "test")
26:
27: # Launch the connection
28: self.client.connect()
29:
30: # The node we are going to publish to
31: self.node = node
32:
33: # Make the application window
34: self.window = gtk.Window()
35: self.window.set_title("PubSub Writer")
36: self.window.connect("destroy", self.destroy)
37: self.vbox = gtk.VBox()
38: self.window.add(self.vbox)
39: self.publish_button = gtk.Button(label="Publish")
40: self.publish_button.connect("released", self.publish)
41: self.vbox.pack_end(self.publish_button)
42: self.entry_box = gtk.TextView()
43: self.vbox.pack_start(self.entry_box)
44:
45: def destroy(self, args):
46: """Quit the application when the window is closed."""
47: gtk.main_quit()
48:
49: def main(self):
50: """The main loop for the application."""
51: self.window.show_all()
52: gobject.timeout_add(250, self.client.process)
53: gtk.main()
54:
55: def publish(self, args):
56: text = self.entry_box.get_buffer().get_text(self.entry_box.get_buffer().get_start_iter(), self.entry_box.get_buffer().get_end_iter())
57: valid_text = simplexml.XMLescape(text)
58: all_text = "<item>" + valid_text + "</item>"
59: print str(valid_text)
60: self.node.publish(self.client, all_text, return_function=self.published)
61:
62: def published(self, reply):
63: print "Reply received"
64: if reply == 0:
65: print "Success!"
66: else:
67: print "Failure :("
68:
69: if __name__ == '__main__':
70: writer = Writer(Node('pubsub.localhost', '/home/localhost/test1/blog/comments'))
71: writer.main()
Generated by git2html.