X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/1a5d9a134e88915b5db447924f532fd63aaeb45e..e8390b9f10338ff5ced700f5dbd87ba30a3566bd:/scripts/conv_genre_families.py?ds=inline diff --git a/scripts/conv_genre_families.py b/scripts/conv_genre_families.py new file mode 100644 index 000000000..611471322 --- /dev/null +++ b/scripts/conv_genre_families.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +from lxml import etree +from slughifi import slughifi +from django.core.management import setup_environ +from wolnelektury import settings + +setup_environ(settings) + +from catalogue.models import Tag + + +doc = etree.parse('rodziny.xml') + +for element in doc.findall('//span'): + themes = [s.strip() for s in element.text.split(',')] + + element.text = u'' + + for theme in themes: + try: + Tag.objects.get(slug=slughifi(theme)) + + link = etree.SubElement(element, 'a', href=u'/katalog/%s' % slughifi(theme)) + link.text = theme + link.tail = ', ' + last_link = link + except: + print "Pomijam %s" % slughifi(theme) + + last_link.tail = '' + + +doc.write('ok.xml', xml_declaration=False, pretty_print=True, encoding='utf-8')