X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/60b06883b6d5a336ef47c01103ec1ce25aafae69..b5d3bba7d1d4ff3efeade1ca9433765fc49a495b:/apps/lesmianator/models.py?ds=sidebyside diff --git a/apps/lesmianator/models.py b/apps/lesmianator/models.py index 5103ebbf1..1b53efdcd 100644 --- a/apps/lesmianator/models.py +++ b/apps/lesmianator/models.py @@ -18,7 +18,6 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django.conf import settings -from librarian import text from catalogue.fields import JSONField from catalogue.models import Book, Tag @@ -126,12 +125,13 @@ class Continuations(models.Model): def for_book(cls, book, length=3): # count from this book only output = StringIO() - f = open(book.xml_file.path) - text.transform(f, output, False, ('raw-text',)) - f.close() + wldoc = book.wldocument(parse_dublincore=False) + output = wldoc.as_text(('raw-text',)).get_string() + del wldoc + conts = {} last_word = '' - for letter in output.getvalue().decode('utf-8').strip().lower(): + for letter in output.decode('utf-8').strip().lower(): mydict = conts.setdefault(last_word, {}) mydict.setdefault(letter, 0) mydict[letter] += 1