Last active
August 29, 2015 14:16
-
-
Save hub-cap/7bdf65a20bf9a3a16d96 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
''' | |
This script takes 2 items. | |
1) Your bitlbee xml file. | |
2) A generated hipchat API user list. | |
''' | |
from sys import argv | |
import simplejson | |
from lxml import etree as et | |
root = et.parse(open(argv[1])) | |
users = {} | |
hipchat_gid = "YOUR HIPCHAT GID" | |
# Gets a list of all your existing buddies | |
for user in root.iterfind('.//buddy'): | |
handle = user.get('handle') | |
if 'hipchat' in handle: | |
uid = handle[handle.index('_')+1:handle.index('@')] | |
users[int(uid)] = user.get('nick') | |
acct = root.find('.//account') | |
json = simplejson.load(open(argv[2])) | |
#Adds <buddy> for any users it didnt find in the above stanza | |
for user in json['items']: | |
if user['id'] not in users: | |
handle = "%s_%s@chat.hipchat.com" % (hipchat_gid, user['id']) | |
mention_name = user['mention_name'] | |
element = et.SubElement(acct, 'buddy', nick=mention_name, handle=handle) | |
root.write(argv[1], xml_declaration=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment