Code Preview
#!/usr/bin/env python3
import random
def spin_text(text):
# Find {option1|option2} patterns
import re
pattern = r'\{([^}]+)\}'
def replace(match):
options = match.group(1).split('|')
return random.choice(options)
return re.sub(pattern, replace, text)
# Example
template = 'Hi {there|John}, I wanted to {reach out|contact you} about {our product|our service}.'
# Generate 5 variations
for i in range(5):
print(f'{i+1}. {spin_text(template)}')
# Full script in download...