#!/usr/bin/env python import random import re def squish(text): "Remove series of spaces from the text." return re.sub('[ \n\t]+', ' ', text).strip() def routput(text, substitution=None): """ Return string with internal word choices replaced randomly. For instance, the string: 'This feels [|very|quite] [nice|cozy|comfortable].' Could return any of the following strings: 'This feels quite nice.' 'This feels cozy.' 'This feels very comfortable.' """ acc = [] for s in text.split("["): selections, *rest = s.split("]") choice = random.choice(selections.split('|')) acc = acc + [choice] + rest return squish(''.join(acc).format(substitution or "")) def choices(text, substitution=None): """ Returns a section of 'text' based on separating semicolons. """ selections = text.split(';;') return routput(random.choice(selections), substitution) def split_party(text, viewer): return text.sub(r"", viewer.name) # def searsonal(text, **kwargs): # season = kwargs['season'] or kwargs['location'].get_season() # time_of_day = kwargs['time_of_day'] or kwargs['location'].get_time_of_day()