Commit a37e4183 authored by Administrator's avatar Administrator

[FEAT] Home page's text is now randomized.

parent a456b482
import random
import random_words
from math import pi
def paragraph_lorem(size_target=450):
'''
Function that returns paragraph with false latin language.
size_target is the number of random words that will be given.
'''
lorem = random_words.LoremIpsum()
sentences_list = lorem.get_sentences_list(sentences=5)
paragraph_size = 0
while paragraph_size < size_target :
sentences_list.append(lorem.get_sentence())
paragraph = ' '.join(sentences_list)
paragraph_size = len(paragraph)
return(paragraph)
def paragraph_gargantua(size_target=500):
'''
Function that returns paragraph with chapter titles of Gargantua.
size_target is the number of random words that will be given.
'''
paragraph = list()
paragraph_size = 0
chapter_number = 1
while paragraph_size < size_target and chapter_number < 6:
chapitre = open('/home/alexandre/bibliotheque/R/Rabelais/Gargantua_chapter_' + str(chapter_number) + '.txt', 'r')
paragraph.append(random.choice(chapitre.readlines()).strip())
chapitre.close()
paragraph_size = len(' '.join(paragraph))
chapter_number += 1
return(' '.join(paragraph))
def random_letter(mot, size_min=6):
'''
Functions that randomize order letters of a
word which size is greater that size_min.
'''
if len(mot) > size_min:
size = round(len(mot) / pi)
first_letters = mot[:size]
last_letters = mot[-size:]
others_letters = list(mot[size:-size])
random.shuffle(others_letters)
mot_list = list()
mot_list.append(first_letters)
for letter in others_letters:
mot_list.append(letter)
mot_list.append(last_letters)
return(''.join(mot_list))
else:
return(mot)
tutoriel = """Il paraît que l'ordre des lettres dans un mot n'a pas d'importance. La première et la dernière lettre doivent être à la bonne place. Le reste peut être dans un désordre total et on peut toujours lire sans problème. On ne lit donc pas chaque lettre en elle-même, mais le mot comme un tout. Un changement de référentiel et nous transposons ce résultat au texte lui-même: l'ordre des mots est faiblement important comparé au contexte du texte qui, lui, est compté"""
def paragraph_tutoreil(tutoriel=tutoriel):
'''
Functions that returns paragraph of words with words with
randomized letters.
'''
paragraph = ' '.join([ random_letter(mot) for mot in tutoriel.split(" ")]) \
+ ": comptexter avec Gargantext."
return(paragraph)
......@@ -24,7 +24,7 @@ urlpatterns = patterns('',
url(r'^css/bootstrap.css$', views.css),
# User Home view
url(r'^$', views.home),
url(r'^$', views.home_view),
url(r'^about/', views.get_about),
url(r'^maintenance/', views.get_maintenance),
......
......@@ -184,8 +184,8 @@ def get_maintenance(request):
return HttpResponse(html)
def home(request):
from gargantext_web import home
def home_view(request):
'''
Home describes the platform.
A video draws the narratives.
......@@ -198,6 +198,9 @@ def home(request):
html = t.render(Context({\
'user': user,\
'date': date,\
'paragraph_gargantua': home.paragraph_gargantua(),\
'paragraph_lorem' : home.paragraph_lorem(),\
'paragraph_tutoreil': home.paragraph_tutoreil(),\
}))
return HttpResponse(html)
......
......@@ -64,32 +64,12 @@
<div class="col-md-4 content">
<h3><a href="#">Historic</a></h3>
<p>
Chapter 1.VI. -- How Gargantua was born in a strange manner.
Chapter 2.XXIII. -- How Pantagruel departed from Paris, hearing
news that the Dipsodes had invaded the land of the Amaurots; and
the cause wherefore the leagues are so short in France. Chapter
3.XLVI. -- How Pantagruel and Panurge diversely interpret the
words of Triboulet. Chapter 4.LV. -- How Pantagruel, being at sea,
heard various unfrozen words. Chapter 5.IX. -- How we arrived at
the island of Tools.
</p>
<p> {{ paragraph_gargantua }}</p>
</div>
<div class="col-md-4 content">
<h3><a href="#">Presentation</a></h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
<p> {{ paragraph_lorem }}
</p>
</div>
......@@ -97,23 +77,9 @@
<div class="col-md-4 content">
<h3><a href="#">Tutoreil</a></h3>
<p>
{{ paragraph_tutoreil }}
<!-- Why not French ? -->
<!-- find Cambridge source which inspired this --!>
Il praaît que l'odrre des ltetres dnas un mot n'a pas
d'iprnorotncae. La pmeirère et la drenèire letrte diovent
êrte à la bnnoe pclae. Le rsete peut êrte dnas un dsérorde
ttoal et on puet tujoruos lrie snas poribême. On ne lit
donc pas chuaqe ltetre en elle-mmêe, mias le mot cmome un
tuot. Un chnagmnet de réfretniel et nuos tarnsposns ce
rselutat au txete lui-mmêe: l'odrre des mtos est faiblement
imoprtnat copmraé au cnotxete du txete qui, lui, est copmté:
comptexter avec Gargantext.
</p>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment