From 453a43082e861318cce9b9e4aa5f0e8d67701240 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 23 May 2012 09:00:04 +0200 Subject: Add lorem --- lorem | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 lorem (limited to 'lorem') diff --git a/lorem b/lorem new file mode 100755 index 0000000..a12df49 --- /dev/null +++ b/lorem @@ -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() -- cgit v1.2.1