Lesmianator
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 13 Sep 2010 10:30:06 +0000 (12:30 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Mon, 13 Sep 2010 10:30:06 +0000 (12:30 +0200)
apps/lesmianator/__init__.py [new file with mode: 0644]
apps/lesmianator/views.py [new file with mode: 0644]
wolnelektury/settings.py
wolnelektury/static/css/master.book.css
wolnelektury/static/img/mats_erikssonCCBYNCSA.jpg [new file with mode: 0644]
wolnelektury/templates/catalogue/main_page.html
wolnelektury/templates/lesmianator/poem.html [new file with mode: 0644]
wolnelektury/urls.py

diff --git a/apps/lesmianator/__init__.py b/apps/lesmianator/__init__.py
new file mode 100644 (file)
index 0000000..0932a1c
--- /dev/null
@@ -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> => <kolejny znak> => <częstość występowania> 
+#
+# 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 (file)
index 0000000..231ab5c
--- /dev/null
@@ -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))
index 9396a1d..b3f3c78 100644 (file)
@@ -132,6 +132,7 @@ INSTALLED_APPS = [
     'rosetta',
     'infopages',
     'suggest',
     'rosetta',
     'infopages',
     'suggest',
+    'lesmianator',
 ]
 
 CACHE_BACKEND = 'locmem:///?max_entries=3000'
 ]
 
 CACHE_BACKEND = 'locmem:///?max_entries=3000'
index 998a8c3..e3b5d8d 100644 (file)
@@ -64,6 +64,20 @@ img {
     color: #000;
     background: #FFF url(/static/img/arrow-up.png) no-repeat center right;
 }
     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;
 
 #toc, #themes {
     position: fixed;
diff --git a/wolnelektury/static/img/mats_erikssonCCBYNCSA.jpg b/wolnelektury/static/img/mats_erikssonCCBYNCSA.jpg
new file mode 100644 (file)
index 0000000..68819f6
Binary files /dev/null and b/wolnelektury/static/img/mats_erikssonCCBYNCSA.jpg differ
index 720c2d5..d503545 100644 (file)
     <div id="intro">
         <p id="tags-description">↓ {% trans "Browse books by categories" %} ↓</p>
         <div id="propaganda">
     <div id="intro">
         <p id="tags-description">↓ {% trans "Browse books by categories" %} ↓</p>
         <div id="propaganda">
-            <p><a href="{% url epub %}"><img src="/static/img/epub-www.jpg" alt="epub: lektury w kieszeni" /></a></p>
+            <!--p><a href="{% url epub %}"><img src="/static/img/epub-www.jpg" alt="epub: lektury w kieszeni" /></a></p-->
+
+            <h2>Leśmianator — poeta automagiczny</h2>
+            <p><img src="/static/img/mats_erikssonCCBYNCSA.jpg" title="{% trans "Author" %}: Mats Eriksson@Flickr, CC BY-NC-SA" /><br/>
+            <cite>Z drogi! — Idzie poeta — niebieski wycieruch!<br/>
+Zbój obłoczny, co z światem jest — wspak i na noże!
+Baczność! — Nic się przed takim uchronić nie może!</cite></p>
+
+<p>Poezja z Wolnych Lektur przepuszczona przez mikser.</p>
+                <p class="see-more"><a href="{% url lesmianator %}">{% trans "Twórz-że się!" %} ⇒</a></p>
 
             <h2>{% trans "Wolne Lektury Widget" %}</h2>
             <p>{% 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:" %}</p>
 
             <h2>{% trans "Wolne Lektury Widget" %}</h2>
             <p>{% 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:" %}</p>
diff --git a/wolnelektury/templates/lesmianator/poem.html b/wolnelektury/templates/lesmianator/poem.html
new file mode 100644 (file)
index 0000000..0d7d712
--- /dev/null
@@ -0,0 +1,38 @@
+{% load i18n %}
+{% load chunks compressed catalogue_tags %}
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+    <head>
+        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+        <title>{% block title %}WolneLektury.pl{% endblock %}</title>
+        <link rel="icon" href="{{ STATIC_URL }}img/favicon.png" type="image/x-icon" />
+        {% compressed_css "book" %}
+    </head>
+    <body>
+        <div id="menu">
+            <a href='' class='menu-link'>Twórz-że się jeszcze raz!</a>
+            <span style='float: right'>Poezja z Wolnych Lektur przepuszczona przez mikser.</a>
+        </div>
+        <div id="header">
+            <div id="logo">
+                <a href="/"><img src="{{ STATIC_URL }}img/logo.png" alt="WolneLektury.pl - logo" /></a>
+            </div>
+        </div>
+        <div id="book-text">
+            <h1>
+                <span class="author">Leśmianator</span>
+                <span class="title">***</span>
+            </h1>
+            {{ object|linebreaksbr }}
+        </div>
+        <script type="text/javascript">
+        var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+        document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+        </script>
+        <script type="text/javascript">
+        var pageTracker = _gat._getTracker("UA-2576694-1");
+        pageTracker._trackPageview();
+        </script>
+    </body>
+</html>
index 05f5638..1a09a0a 100644 (file)
@@ -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'^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'),
 
     # Static pages
     url(r'^wolontariat/$', 'infopages.views.infopage', {'slug': 'voluntary_services'}, name='voluntary_services'),