Created
July 21, 2021 22:16
-
-
Save driazati/b8864a73229f2071b5c0424349084a59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
import random | |
content = open(sys.argv[1]).read() | |
def gen_meow(word): | |
chars_to_add = len(word) - len("meow") | |
if chars_to_add <= 0: | |
return "meow" | |
base = "meow" | |
counts = [1 for x in range(len(base))] | |
while chars_to_add > 0: | |
index = random.randint(0, len(counts) - 1) | |
should_add = random.randint(0, 10) | |
if should_add > 5: | |
counts[index] += 1 | |
chars_to_add -= 1 | |
newmeow = "" | |
for index, count in enumerate(counts): | |
newmeow += base[index] * count | |
return newmeow | |
def replace_word(match): | |
word = match.group() | |
meow = gen_meow(word) | |
if word.isupper(): | |
return meow.upper() | |
if word[0].isupper(): | |
return meow[0].upper() + meow[1:] | |
return meow | |
def remove_linebreaks(match): | |
return " " + match.groups()[0] | |
content = re.sub(r"(?<!\n)\n(?!\s)", " ", content, flags=re.MULTILINE) | |
content = re.sub(r'[a-zA-Z]+', replace_word, content) | |
content = re.sub(r"\n\n", "\n", content, flags=re.MULTILINE) | |
out = "" | |
for c in content: | |
hyp = "" | |
if random.randint(0, 10) < 3: | |
hyp += bytes([0xc2, 0xad]).decode("utf-8") | |
out += c + hyp | |
content = out | |
open("book_out.txt", "w").write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment