From: Radek Czajka Date: Mon, 13 Sep 2010 10:30:06 +0000 (+0200) Subject: Lesmianator X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/4dc96918a2e2df441c282a7abbb89235ecb4f2f7 Lesmianator --- diff --git a/apps/lesmianator/__init__.py b/apps/lesmianator/__init__.py new file mode 100644 index 000000000..0932a1c6e --- /dev/null +++ b/apps/lesmianator/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Leśmianator do działania wymaga pliku dictionary.p w katalogu aplikacji +# plik ten powinien zawierać słownik postaci: +# <3-znakowy ciąg> => => +# +# automat generujący taki słownik zostanie dodany później :) diff --git a/apps/lesmianator/views.py b/apps/lesmianator/views.py new file mode 100644 index 000000000..231ab5c96 --- /dev/null +++ b/apps/lesmianator/views.py @@ -0,0 +1,52 @@ +# Create your views here. + +import pickle +from django.shortcuts import render_to_response +from django.template import RequestContext +from random import randint + +import os.path + + +def _choose_word(word): + try: + choices = sum((_dictionary[word][post] for post in _dictionary[word])) + r = randint(0, choices - 1) + + for post in _dictionary[word]: + r -= _dictionary[word][post] + if r < 0: + return post + except KeyError: + return '' + +# load dictionary on start, it won't change +try: + f = open(os.path.join(os.path.dirname(__file__), 'dictionary.p')) + _dictionary = pickle.load(f) +except: + _dictionary = {} + + +def poem(request): + letters = [] + word = u'' + empty = -10 + left = 1000 + if not _dictionary: + left = 0 + while empty != 3 and left: + letter = _choose_word(word) + letters.append(letter) + word = word[-2:] + letter + if letter == u'\n': + empty += 1 + else: + empty = 0 + left -= 1 + + poem = ''.join(letters).strip() + + return render_to_response('lesmianator/poem.html', + {"object": poem}, + context_instance=RequestContext(request)) diff --git a/wolnelektury/settings.py b/wolnelektury/settings.py index 9396a1dd1..b3f3c7827 100644 --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@ -132,6 +132,7 @@ INSTALLED_APPS = [ 'rosetta', 'infopages', 'suggest', + 'lesmianator', ] CACHE_BACKEND = 'locmem:///?max_entries=3000' diff --git a/wolnelektury/static/css/master.book.css b/wolnelektury/static/css/master.book.css index 998a8c374..e3b5d8db8 100644 --- a/wolnelektury/static/css/master.book.css +++ b/wolnelektury/static/css/master.book.css @@ -64,6 +64,20 @@ img { color: #000; background: #FFF url(/static/img/arrow-up.png) no-repeat center right; } +#menu a.menu-link { + display: block; + float: left; + height: 1.5em; + margin-left: 0.5em; + text-align: center; + color: #FFF; +} +#menu span { + color: #888; + font-style: italic; + font-size: .75em; +} + #toc, #themes { position: fixed; diff --git a/wolnelektury/static/img/mats_erikssonCCBYNCSA.jpg b/wolnelektury/static/img/mats_erikssonCCBYNCSA.jpg new file mode 100644 index 000000000..68819f63c Binary files /dev/null and b/wolnelektury/static/img/mats_erikssonCCBYNCSA.jpg differ diff --git a/wolnelektury/templates/catalogue/main_page.html b/wolnelektury/templates/catalogue/main_page.html index 720c2d584..d5035450e 100644 --- a/wolnelektury/templates/catalogue/main_page.html +++ b/wolnelektury/templates/catalogue/main_page.html @@ -16,7 +16,16 @@

↓ {% trans "Browse books by categories" %} ↓

-

epub: lektury w kieszeni

+ + +

Leśmianator — poeta automagiczny

+


+ Z drogi! — Idzie poeta — niebieski wycieruch!
+Zbój obłoczny, co z światem jest — wspak i na noże! +Baczność! — Nic się przed takim uchronić nie może!

+ +

Poezja z Wolnych Lektur przepuszczona przez mikser.

+

{% trans "Twórz-że się!" %} ⇒

{% trans "Wolne Lektury Widget" %}

{% trans "Place our widget - search engine for Wolne Lektury which gives access to free books and audiobooks - on your homepage! Just copy the HTML code below onto your page:" %}

diff --git a/wolnelektury/templates/lesmianator/poem.html b/wolnelektury/templates/lesmianator/poem.html new file mode 100644 index 000000000..0d7d712d7 --- /dev/null +++ b/wolnelektury/templates/lesmianator/poem.html @@ -0,0 +1,38 @@ +{% load i18n %} +{% load chunks compressed catalogue_tags %} + + + + + {% block title %}WolneLektury.pl{% endblock %} + + {% compressed_css "book" %} + + + + +
+

+ Leśmianator + *** +

+ {{ object|linebreaksbr }} +
+ + + + diff --git a/wolnelektury/urls.py b/wolnelektury/urls.py index 05f5638b7..1a09a0ad5 100644 --- a/wolnelektury/urls.py +++ b/wolnelektury/urls.py @@ -16,6 +16,7 @@ urlpatterns = patterns('', url(r'^katalog/', include('catalogue.urls')), url(r'^materialy/', include('lessons.urls')), url(r'^sugestia/', include('suggest.urls')), + url(r'^lesmianator/?$', 'lesmianator.views.poem', name='lesmianator'), # Static pages url(r'^wolontariat/$', 'infopages.views.infopage', {'slug': 'voluntary_services'}, name='voluntary_services'),