shuffle
code
Python
verified
Free Download
devices
Cross-platform
code Code Preview
Python#!/usr/bin/env python3
"""
Spin Text Generator
Generate A/B testing variations from spin syntax templates
"""
import random
import re
def spin_text(text):
"""Replace {option1|option2} patterns with random choice"""
pattern = r'\{([^}]+)\}'
def replace(match):
options = match.group(1).split('|')
return random.choice(options)
return re.sub(pattern, replace, text)
def generate_variations(template, count=5):
"""Generate multiple unique variations"""
variations = set()
attempts = 0
max_attempts = count * 10
while len(variations) < count and attempts < max_attempts:
variation = spin_text(template)
variations.add(variation)
attempts += 1
return list(variations)
def count_possible_variations(template):
"""Count total possible unique variations"""
pattern = r'\{([^}]+)\}'
matches = re.findall(pattern, template)
total = 1
for match in matches:
options = match.split('|')
total *= len(options)
return total
def validate_template(template):
"""Validate spin syntax is correct"""
open_braces = template.count('{')
close_braces = template.count('}')
if open_braces != close_braces:
return False, "Mismatched braces"
# Check for empty options
if '||' in template or '{|' in template or '|}' in template:
return False, "Empty option found"
return True, "Valid template"
if __name__ == '__main__':
template = '''Hi {there|John|friend},
I wanted to {reach out|connect|touch base} about {our product|our service|working together}.
{Would you be free|Could we schedule|Do you have time} for a {quick call|brief chat|15-minute meeting}?
{Best|Regards|Thanks},
{Alex|The Team}'''
print(f"Possible variations: {count_possible_variations(template)}")
print("\nGenerated variations:")
for i, var in enumerate(generate_variations(template, 3), 1):
print(f"\n--- Version {i} ---")
print(var)
info About This Tool
The Spin Text Generator creates multiple email variations from a single template using spin syntax. Perfect for A/B testing and avoiding duplicate content detection.
Spin Syntax
{option1|option2|option3}- Random selection- Nest anywhere in your text
- Multiple spin blocks per template
Key Features
- Multiple Variations - Generate unlimited unique versions
- Variation Counter - Shows total possible combinations
- Validation - Checks syntax before processing
- Deduplication - Ensures unique outputs
- Bulk Export - Generate CSV of variations
Use Cases
- A/B Testing - Test different subject lines and CTAs
- Anti-Spam - Unique content avoids filters
- Personalization - Dynamic greeting variations
Requirements
- Python 3.7+
- No external dependencies
Note: Use responsibly. Spin text should enhance genuine outreach, not disguise spam.
download Download Script
Need Full Automation?
Try Postigo for automated email campaigns with AI personalization
rocket_launch Start Free Trial