author Da Risk <>
Sat, 29 Sep 2012 04:47:42 +0200
changeset 995 6318bee856fd
child 1004 aa8c2dac6d02
permissions -rwxr-xr-x
Display error messages when account creation failed. Improve the creation wizard and add a dummy script to fetch a list of xmpp services.

#!/usr/bin/env python3

import urllib.request
import argparse, sys
from xml.dom.minidom import parse, getDOMImplementation

def getJidsFromUrl(url):
    f = urllib.request.urlopen(url)
    indoc = parse(f)
    jids = []
    query = indoc.documentElement
    if query.localName == "query" :
        for item in query.getElementsByTagName("item"):
            jid = item.getAttribute("jid")
    return jids

def createDocument():
    impl = getDOMImplementation()
    return impl.createDocument(None, "resources", None)

def purge(elems):
    res = []
    for i in elems:
        if i not in res:
    return res

def appendStringElem(doc, node, jids):
    for i in jids:
        item = doc.createElement("item")
        text = doc.createTextNode(i)

parser = argparse.ArgumentParser(description='Collect some free xmpp services')
parser.add_argument('url', metavar="url",
        default=['', ""] , nargs='*',
        help='url to get the services')

parser.add_argument('-o', metavar="FILE", type=argparse.FileType('bw'),
        default = sys.stdout.buffer,
        help='send output to FILE')

args = parser.parse_args()

# collect the servers jid
jids = []
for url in args.url:
    jids += getJidsFromUrl(url)

jids = purge(jids)

# create the xml output document
outdoc = createDocument()
res_element = outdoc.documentElement
string_array_elem = outdoc.createElement('string-array')
string_array_elem.setAttribute("name", "xmpp_server_list")
appendStringElem(outdoc, string_array_elem, jids)

# print result
f = args.o