Skip to content

Instantly share code, notes, and snippets.

@mardix
Created January 16, 2017 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mardix/73a1b4bb47dde7926890e736bb12aa13 to your computer and use it in GitHub Desktop.
Save mardix/73a1b4bb47dde7926890e736bb12aa13 to your computer and use it in GitHub Desktop.
# 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/%s.md' % (outputDir, getRandomDate()), 'w') as f:
f.write('---\n')
f.write('title: %s\n' % title)
f.write('description: %s\n' % desc)
f.write('slug: %s\n' % slug)
f.write('---\n\n')
# Generate blocks of random words
num_paragraphs = random.randint(5, 10)
for i in range(num_paragraphs):
f.write(generateSentence(random.randint(50, 100)))
f.write('\n\n')
# Set defaults
outputDir = "./test.com/pages"
numPosts = 1000
def generate():
if os.path.isdir(outputDir):
shutil.rmtree(outputDir)
os.makedirs(outputDir)
for i in range(numPosts):
createPost(outputDir)
generate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment