Changed check if HTML file should be generated to search for //div.
[wolnelektury.git] / conv_genre_families.py
1 # -*- coding: utf-8 -*-
2 from lxml import etree
3 from slughifi import slughifi
4 from django.core.management import setup_environ
5 from wolnelektury import settings
6
7 setup_environ(settings)
8
9 from catalogue.models import Tag
10
11
12 doc = etree.parse('rodziny.xml')
13
14 for element in doc.findall('//span'):
15     themes = [s.strip() for s in element.text.split(',')]
16     
17     element.text = u''
18     
19     for theme in themes:
20         try:
21             Tag.objects.get(slug=slughifi(theme))
22         
23             link = etree.SubElement(element, 'a', href=u'/katalog/%s' % slughifi(theme))
24             link.text = theme
25             link.tail = ', '
26             last_link = link
27         except:
28             print "Pomijam %s" % slughifi(theme)
29
30     last_link.tail = ''
31
32
33 doc.write('ok.xml', xml_declaration=False, pretty_print=True, encoding='utf-8')