aaaaa

mail@pastecode.io avatar
unknown
python
8 months ago
2.8 kB
2
Indexable
Never
import re 
import random 
 
def parse_spintax(text, num_variations): 
 pattern = r'\{([^{}]+)\}' 
 matches = re.findall(pattern, text) 
 variations = [] 
 for match in matches: 
 options = match.split('|') 
 variations.append(options) 
 parsed_texts = set() 
 while len(parsed_texts) < num_variations: 
 parsed_text = text 
 for options in variations: 
 selected_option = random.choice(options) # Выбираем случайную опцию 
 parsed_text = parsed_text.replace("{" + "|".join(options) + "}", selected_option, 1) 
 if parsed_text not in parsed_texts:
    parsed_texts.add(parsed_text) 
 if len(parsed_texts) == num_variations: 
 break 
 # Перемешиваем варианты для следующей итерации 
 random.shuffle(variations) 
 return parsed_texts 
 
text_with_spintax = '''{Hello|Hi} Name, 
 
My name is Scott, and {I am a manager at Ledger|my role is manager at Ledger}. 
I am {pleased|excited} to contact you with an {offer|invitation} to join our {team|company}. 
 
After {carefully reviewing|thoroughly examining} your experience and LinkedIn profile, we are confident that your proficiency and {knowledge|skills} align with our requirements. We are looking for {talented|skilled} and ambitious {experts|individuals}, and you seem to be just such a {person|candidate}. 
 
Ledger guarantees not only {career development|professional growth} but also a {competitive|attractive} salary. We are {delighted|pleased} to announce that we provide the opportunity to work remotely, giving you the flexibility to {organize|manage} your {work process|workflow}. 
 
In addition to salary, our {employees|team members} receive a variety of {bonuses|additional rewards|benefits} and {incentive payments|motivational incentives} to help them achieve their goals, and we're {confident|sure} that these additional benefits will make your experience at Ledger even more rewarding and {motivational|inspiring}. 
 
If you are interested in discussing {partnership opportunities|collaborative prospects}, please let us know. We look forward to getting to know you personally and discussing how you can contribute to our company. 
 
{Thank you|Thanks} for your {consideration|attention}, and we look for a {positive|affirmative} {response|reply} from you. 
 
{All the best|Best Regards|Best Wishes}, 
{Scott|Scott Johnson}
''' 
 
num_variations = 10 
parsed_variations = parse_spintax(text_with_spintax, num_variations) 
 
with open('skazka.txt', 'w') as file: 
 for i, variation in enumerate(parsed_variations, start=1): 
 variation = re.sub(r'\{|\}', '', variation) # Удаление символов '{' и '}' 
 file.write(f"{i}. {variation}\n") 
 
print("500 variations have been saved in 'skazka.txt'.")
Leave a Comment