#!/usr/bin/python

import string, sys, random

dict = "propernames"
feed = '<rss version="2.0" xml:lang="en"><channel>%s</channel></rss>'
item = '<item><title>%s</title><id>%s</id><description>%s</description></item>'

def main(args):
    db = loaddb()
    sp = len(db)/5
    st = []
    for i in range(5):
        j = i*sp
        st.append(db[j:j+sp])
    for i in range(len(st)):
        try:
            fh = open('trivial-%d.xml' % i,'w')
            fh.write(
                feed % (
                    string.join(
                        [item % (
                            'Cluster-#%d, Article-#%d' % (i,j),
                            '%d-%d' % (i,j),
                            string.join([st[i][random.randrange(sp)] for x in range(sp)],','))
                        for j in range(10)],"\n"
                    )
                )
            )
        finally:
            fh.close()

def intersection(x1,x2):
    for i in x1:
        for j in x2:
            if i==j:
                print i
def loaddb():
    global dict
    try:
        fh = open(dict,'r')
        return map(string.strip,fh.readlines())
    finally:
        fh.close()

if __name__ == '__main__':
    main(sys.argv)
