def generate(type, count, startWithLorem): sentences_count = 0 words_count = 0 if type == 'paragraphs': text = '' paragraphs = loremipsum.generate_paragraphs(count, startWithLorem) for paragraph in paragraphs: sentences_count += paragraph[0] words_count += paragraph[1] text += paragraph[2] + '\n\n' elif type == 'sentences': text = '' sentences = loremipsum.generate_sentences(count, startWithLorem) for sentence in sentences: sentences_count += sentence[0] words_count += sentence[1] text += sentence[2] + ' ' else: paragraphs = generate('paragraphs', 110, startWithLorem)[1] if count > 1000: count = 1000 words_count += count text = ' '.join(paragraphs.split()[:count]) stats = 'Generated' if sentences_count: stats += ' %s sentences' % (sentences_count) if words_count: stats += ' %s words' % (words_count) return [stats, text.strip()]
def generate(type, count, startWithLorem): sentences_count = 0 words_count = 0 if type == "paragraphs": text = "" paragraphs = loremipsum.generate_paragraphs(count, startWithLorem) for paragraph in paragraphs: sentences_count += paragraph[0] words_count += paragraph[1] text += paragraph[2] + "\n\n" elif type == "sentences": text = "" sentences = loremipsum.generate_sentences(count, startWithLorem) for sentence in sentences: sentences_count += sentence[0] words_count += sentence[1] text += sentence[2] + " " else: paragraphs = generate("paragraphs", 110, startWithLorem)[1] if count > 1000: count = 1000 words_count += count text = " ".join(paragraphs.split()[:count]) stats = "Generated" if sentences_count: stats += " %s sentences" % (sentences_count) if words_count: stats += " %s words" % (words_count) return [stats, text.strip()]
def test_generate_paragraphs(self): """Test loremipsum.generate_paragraphs function.""" gen = loremipsum.generate_paragraphs( 100, incipit=True, paragraph_mean=0.1, paragraph_sigma=0.1) self.assertIsInstance(gen, types.GeneratorType) paragraphs = list(gen) self.assertEqual(len(paragraphs), 100) for paragraph_len, words, text in paragraphs: self.assertEqual(paragraph_len, 2)
def main(): # Random 2D list table = [[random.randint(0, 100) for j in range(10)] for i in range(10)] # Some Lorem Ipsum text paragraphs = [p[2] for p in generate_paragraphs(3)] html = render_template("report.html", table=table, paragraphs=paragraphs) print_pdf(html, "file.pdf")
def test_generate_paragraphs(self): """Test loremipsum.generate_paragraphs function.""" gen = loremipsum.generate_paragraphs(100, incipit=True, paragraph_mean=0.1, paragraph_sigma=0.1) self.assertIsInstance(gen, types.GeneratorType) paragraphs = list(gen) self.assertEqual(len(paragraphs), 100) for paragraph_len, words, text in paragraphs: self.assertEqual(paragraph_len, 2)
def create_topic(cafe_id, user_id): title = loremipsum.generate_sentence()[2] paragraphs = loremipsum.generate_paragraphs(random.randint(3, 7)) paragraphs = [p[2] for p in paragraphs] md_content = random.choice(markdown_contents) index = random.randint(0, len(paragraphs)) paragraphs.insert(index, md_content) content = '\n\n'.join(paragraphs) return { "title": title[:135], "content": content, "user_id": user_id, }
def iter_comments(): print('Creating comments') def sub(text): count = random.randint(10, 200) return text[:count] for i in range(1, 2400): paragraphs = loremipsum.generate_paragraphs(random.randint(1, 3)) content = '\n\n'.join(sub(p[2]) for p in paragraphs) yield { "topic_id": random.randint(400, 600), "user_id": random.randint(2, 1000), "content": content[:400] }
def html(self, fake_content=False, view=None): """Returns the html""" if view is None: view = self.view if fake_content: paragraphs = generate_paragraphs(5, start_with_lorem=False) p = "" for paragraph in paragraphs: p = unicode(paragraph[2]) + "\n\n" + p return creole2html(p) # The view object is actually passed to the macro being called such that # it can manipulate the view object to update it. return creole2html( self.raw_content, macros={ "code": code, "pre": pre, "html": html, "HTML": HTML, "H1": H1, "H2": H2, "alertblock": alertblock, "alertsuccess": alertsuccess, "alertinfo": alertinfo, "alerterror": alertwarning, "infoblock": infoblock, "image": image, "debug": debug, "google_addsense_code": google_addsense_code, "imagelist": imagelist, "NEWLINE": NEWLINE, }, verbose=None, stderr=None, view=view, )
def generate_file(filename, N=4, separator='\n\n'): with open(filename, 'w') as outfile: for _, _, text in loremipsum.generate_paragraphs(N): outfile.write(text + separator)
def get_blob(): res = '' for p in generate_paragraphs(10, False): res += p[2] return res
#!/usr/bin/env python from apiclient.discovery import build import loremipsum guestbook = build('guestbook', 'v1', discoveryServiceUrl="https://atlantean-field-90117.appspot.com/_ah/api/discovery/v1/apis/{api}/{apiVersion}/rest") dir(guestbook) guestbook.listPosts().execute() for i in range(0, 100): print "Filling: %d/%d" % (i, 100) name = "Lorem: %d" % i body = '\n\n'.join(i[2] for i in loremipsum.generate_paragraphs(3)) guestbook.createPost(body={"body":body, "name":name}).execute() pass
#!/usr/bin/env python from apiclient.discovery import build import loremipsum guestbook = build( 'guestbook', 'v1', discoveryServiceUrl= "https://atlantean-field-90117.appspot.com/_ah/api/discovery/v1/apis/{api}/{apiVersion}/rest" ) dir(guestbook) guestbook.listPosts().execute() for i in range(0, 100): print "Filling: %d/%d" % (i, 100) name = "Lorem: %d" % i body = '\n\n'.join(i[2] for i in loremipsum.generate_paragraphs(3)) guestbook.createPost(body={"body": body, "name": name}).execute() pass