get_lemmas_list.py
838 Bytes
# -*- coding:utf-8 -*-
import codecs
import datetime
import os
from django.core.management.base import BaseCommand
from dictionary.models import Lemma
from settings import PROJECT_PATH
POS = 'verb'
OUTPATH = os.path.join(PROJECT_PATH, 'data', '%ss-%s.txt' % (POS, datetime.datetime.now().strftime('%Y%m%d')))
class Command(BaseCommand):
help = 'Get lemmas existing in Walenty'
def handle(self, *args, **options):
lemmas = Lemma.objects.filter(old=False, entry_obj__pos__tag=POS)
lemmas = lemmas.exclude(status__status=u'do usunięcia').order_by('entry_obj__name')
write_lemmas(lemmas)
def write_lemmas(lemmas):
try:
outfile = codecs.open(OUTPATH, 'w', 'utf-8')
for lemma in lemmas:
outfile.write('%s\n' % lemma.entry_obj.name)
finally:
outfile.close()