Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Allow to create pages for testing purposes
from datetime import datetime
import random
import string
import shutil
import os
def generateWord():
length = random.randint(1, 10)
word = ''.join(random.choice(string.letters) for _ in range(length))
return word
def generateSentence(words):
return ' '.join([generateWord() for i in range(words)])
def getRandomDate():
year = random.choice(range(1950, 2017))
month = random.choice(range(1, 13))
day = random.choice(range(1, 29))
hours = random.choice(range(0, 24))
minutes = random.choice(range(0, 60))
seconds = random.choice(range(0, 60))
return datetime(year, month, day, hours, minutes, seconds).strftime("%Y-%m-%d_%H-%M-%S")
def createPost(outputDir):
title = generateSentence(8)
desc = generateSentence(20)
slug = title.replace(' ', '-').lower()
slug = ''.join(c for c in slug if c.isalnum() or c == '-')
with open('%s/' % (outputDir, getRandomDate()), 'w') as f:
f.write('title: %s\n' % title)
f.write('description: %s\n' % desc)
f.write('slug: %s\n' % slug)
# Generate blocks of random words
num_paragraphs = random.randint(5, 10)
for i in range(num_paragraphs):
f.write(generateSentence(random.randint(50, 100)))
# Set defaults
outputDir = "./"
numPosts = 1000
def generate():
if os.path.isdir(outputDir):
for i in range(numPosts):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment