1 # Create your views here.
4 from django.shortcuts import render_to_response
5 from django.template import RequestContext
6 from random import randint
9 def _choose_word(word):
11 choices = sum((_dictionary[word][post] for post in _dictionary[word]))
12 r = randint(0, choices - 1)
14 for post in _dictionary[word]:
15 r -= _dictionary[word][post]
21 # load dictionary on start, it won't change
22 from django.conf import settings
25 f = open(settings.LESMIANATOR_PICKLE)
26 _dictionary = cPickle.load(f)
39 # want at least two lines, but let Lesmianator end his stanzas
40 while (empty < 2 or lines < 2) and left:
41 letter = _choose_word(word)
42 letters.append(letter)
43 word = word[-2:] + letter
45 # count non-empty lines
56 poem = ''.join(letters).strip()
58 return render_to_response('lesmianator/poem.html',
60 context_instance=RequestContext(request))