
Untitled
By: a guest on
Aug 22nd, 2012 | syntax:
None | size: 1.46 KB | hits: 6 | expires: Never
"""
forked from django.contrib.webdesign.lorem_ipsum
https://github.com/django/django/blob/master/django/contrib/webdesign/lorem_ipsum.py
import instagram
for p in instagram.paragraphs(6):
print p+"\n"
"""
import random
def sentence():
"""
Returns a randomly generated sentence of lorem ipsum text.
The first word is capitalized, and the sentence ends in either a period or
question mark. Commas are added at random.
"""
# Determine the number of comma-separated sections and number of words in
# each section for this sentence.
sections = [random.choice([u'instagram', u'facebook']) for i in range(random.randint(1, 5))]
s = u', '.join(sections)
# Convert to sentence case and add end punctuation.
return u'%s%s%s' % (s[0].upper(), s[1:], random.choice('?.'))
def paragraph():
"""
Returns a randomly generated paragraph of lorem ipsum text.
The paragraph consists of between 1 and 4 sentences, inclusive.
"""
return u' '.join([sentence() for i in range(random.randint(1, 4))])
def paragraphs(count, common=True):
"""
Returns a list of paragraphs as returned by paragraph().
If `common` is True, then the first paragraph will be the standard
'lorem ipsum' paragraph. Otherwise, the first paragraph will be random
Latin text. Either way, subsequent paragraphs will be random Latin text.
"""
paras = []
for i in range(count):
paras.append(paragraph())
return paras