diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-05-23 09:00:04 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-05-23 09:00:04 +0200 |
commit | 453a43082e861318cce9b9e4aa5f0e8d67701240 (patch) | |
tree | a68e5ecd950ba9f44320104ef01cbec4ed8940aa /lorem | |
parent | e8bfb185b5e1eb495076983eb2a4440318cb5b57 (diff) | |
download | extrautils-453a43082e861318cce9b9e4aa5f0e8d67701240.tar.gz |
Add lorem
Diffstat (limited to 'lorem')
-rwxr-xr-x | lorem | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -0,0 +1,49 @@ +#!/usr/bin/python + +import cliapp +import random +import textwrap + + +wrapped_text = ''' +Lorem ipsum dolor sit amet, consectetur adipisicing 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. +''' + + +class Lorem(cliapp.Application): + + max_sentences = 8 + + def add_settings(self): + self.settings.integer( + ['paragraphs', 'p'], + 'number of paragraphs to produce, approximately; each paragraph ' + 'is of a random, but fairly short length ' + '(default is infinite)', + metavar='N') + + def process_args(self, args): + text = ' '.join(x for x in wrapped_text.split('\n') if x) + sentences = [x for x in text.split('.') if x] + sentences = [' '.join(x.split()) + '.' for x in sentences] + + i = 0 + paragraphs = self.settings['paragraphs'] + while True: + n = random.randint(1, self.max_sentences) + paragraph = '\n'.join(random.choice(sentences) for i in range(n)) + self.output.write('\n'.join(textwrap.wrap(paragraph))) + self.output.write('\n') + i += 1 + if paragraphs and i >= paragraphs: + break + # Output empty line only between paragraphs, not after the last. + self.output.write('\n') + + +Lorem().run() |