Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 22nd, 2012  |  syntax: None  |  size: 1.46 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. """
  3. forked from django.contrib.webdesign.lorem_ipsum
  4.  
  5. https://github.com/django/django/blob/master/django/contrib/webdesign/lorem_ipsum.py
  6.  
  7.  
  8.     import instagram
  9.     for p in instagram.paragraphs(6):
  10.         print p+"\n"
  11. """
  12.  
  13. import random
  14.  
  15. def sentence():
  16.     """
  17.     Returns a randomly generated sentence of lorem ipsum text.
  18.  
  19.     The first word is capitalized, and the sentence ends in either a period or
  20.     question mark. Commas are added at random.
  21.     """
  22.     # Determine the number of comma-separated sections and number of words in
  23.     # each section for this sentence.
  24.     sections = [random.choice([u'instagram', u'facebook']) for i in range(random.randint(1, 5))]
  25.     s = u', '.join(sections)
  26.     # Convert to sentence case and add end punctuation.
  27.     return u'%s%s%s' % (s[0].upper(), s[1:], random.choice('?.'))
  28.  
  29. def paragraph():
  30.     """
  31.     Returns a randomly generated paragraph of lorem ipsum text.
  32.  
  33.     The paragraph consists of between 1 and 4 sentences, inclusive.
  34.     """
  35.     return u' '.join([sentence() for i in range(random.randint(1, 4))])
  36.  
  37. def paragraphs(count, common=True):
  38.     """
  39.     Returns a list of paragraphs as returned by paragraph().
  40.  
  41.     If `common` is True, then the first paragraph will be the standard
  42.     'lorem ipsum' paragraph. Otherwise, the first paragraph will be random
  43.     Latin text. Either way, subsequent paragraphs will be random Latin text.
  44.     """
  45.     paras = []
  46.     for i in range(count):
  47.         paras.append(paragraph())
  48.     return paras