X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/6ec15224f3482ea18d339df7e2acc160d799be43..adfc9d2b19ec27d32d5e4dd3ceba16d1fe51fcc9:/scripts/genslugs?ds=sidebyside diff --git a/scripts/genslugs b/scripts/genslugs index 0957da7..9745b68 100755 --- a/scripts/genslugs +++ b/scripts/genslugs @@ -2,8 +2,10 @@ # -*- coding: utf-8 -*- # # This file is part of Librarian, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from __future__ import print_function, unicode_literals + import os import optparse @@ -26,7 +28,7 @@ if __name__ == '__main__': help='print status messages to stdout') parser.add_option('-f', '--force', action='store_true', dest='force', default=False, help='overwrite current identifiers') - + options, input_filenames = parser.parse_args() if len(input_filenames) < 1: @@ -36,15 +38,15 @@ if __name__ == '__main__': # Do some real work for input_filename in input_filenames: if options.verbose: - print input_filename - + print(input_filename) + doc = etree.parse(input_filename) try: title = doc.find('//{http://purl.org/dc/elements/1.1/}title').text except AttributeError: - print '%s:error:Book title not found. Skipping.' % input_filename + print('%s:error:Book title not found. Skipping.' % input_filename) continue - + parent = '' try: parent_url = doc.find('//{http://purl.org/dc/elements/1.1/}relation.isPartOf').text @@ -52,16 +54,16 @@ if __name__ == '__main__': except AttributeError: pass except IndexError: - print '%s:error:Invalid parent URL "%s". Skipping.' % (input_filename, parent_url) - + print('%s:error:Invalid parent URL "%s". Skipping.' % (input_filename, parent_url)) + book_url = doc.find('//{http://purl.org/dc/elements/1.1/}identifier.url') if book_url is None: book_description = doc.find('//{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description') book_url = etree.SubElement(book_description, '{http://purl.org/dc/elements/1.1/}identifier.url') if not options.force and book_url.text.startswith('http://'): - print '%s:Notice:Book already has identifier URL "%s". Skipping.' % (input_filename, book_url.text) + print('%s:Notice:Book already has identifier URL "%s". Skipping.' % (input_filename, book_url.text)) continue - + book_url.text = BOOK_URL + slughifi(parent + title)[:60] doc.write(input_filename, xml_declaration=True, pretty_print=True, encoding='utf-8')