Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import re
  2. import string
  3. import random
  4.  
  5. galt = open('galt.txt', 'r').readlines()
  6. output = open('output.txt', 'w')
  7. words = ["epsilon", "eps", "si", "sil", "lon", "silon", "epsil", "ep", "lo", "on", "plus", "plu", "pl", "us"]
  8. punctuation = re.compile(r"\W+")
  9.  
  10. for line in galt:
  11.     line = re.split(r'(\W+)', line) # this seems to fail if the parens are removed but, idk
  12.    
  13.     if line != ['', '\n', '']:
  14.         line.pop()
  15.         line[-1] = line[-1][0:len(line[-1]) - 2]
  16.         temp_output = ""
  17.         for word in line:
  18.             if word == '':
  19.                 pass
  20.             elif re.match(punctuation, word):
  21.                 temp_output += word
  22.             elif word == "John" or word == "Galt":
  23.                 temp_output += word
  24.             else:
  25.                 if word.islower():
  26.                     temp_output += random.choice(words)
  27.                 else:
  28.                     temp_output += random.choice(words).capitalize()
  29.         if temp_output[-1] != '.':
  30.             temp_output += '.'
  31.         if temp_output[0] == '“':
  32.             temp_output += '“'
  33.         temp_output += '\n\n'
  34.         output.write(temp_output)
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement