Last active
August 29, 2015 14:00
-
-
Save atdt/258f0994f988870a3bd5 to your computer and use it in GitHub Desktop.
rcxml.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
RCStream JSON -> XML transformer | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
Dependencies: | |
* dicttoxml - https://github.com/quandyfactory/dicttoxml | |
* socketIO-client - https://pypi.python.org/pypi/socketIO-client | |
To install dependencies automatically, run: | |
# pip install dicttoxml socketIO-client | |
Copyright 2014 Ori Livneh <ori@wikimedia.org> | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
""" | |
import dicttoxml | |
import socketIO_client | |
class WikiNamespace(socketIO_client.BaseNamespace): | |
def on_change(self, change): | |
xml = dicttoxml.dicttoxml(change) | |
dom = dicttoxml.parseString(xml) | |
print dom.toprettyxml() | |
def on_connect(self): | |
print 'connected!' | |
self.emit('subscribe', '*') | |
socketIO = socketIO_client.SocketIO('rcstream.wmflabs.org', 80) | |
socketIO.define(WikiNamespace, '/rc') | |
socketIO.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment