1 # Create your views here.
4 from django.shortcuts import render_to_response
5 from django.template import RequestContext
6 from random import randint
11 def _choose_word(word):
13 choices = sum((_dictionary[word][post] for post in _dictionary[word]))
14 r = randint(0, choices - 1)
16 for post in _dictionary[word]:
17 r -= _dictionary[word][post]
23 # load dictionary on start, it won't change
25 f = open(os.path.join(os.path.dirname(__file__), 'dictionary.p'))
26 _dictionary = pickle.load(f)
38 while empty != 3 and left:
39 letter = _choose_word(word)
40 letters.append(letter)
41 word = word[-2:] + letter
48 poem = ''.join(letters).strip()
50 return render_to_response('lesmianator/poem.html',
52 context_instance=RequestContext(request))