#!/usr/bin/python import sys # Magic contraction dictionary: contractions = { "fuck" : "nerf", \ "shit" : "bad", \ "whore" : "nerf", \ "bastard" : "bad" \ "fucker" : "nerfer" \ "fucking" : "nerfing" \ "cock" : "jerk" \ "motherfucker" : "terrible" \ "pirate" : "ninja" \ } def lamonize(victim, replacement=contractions): for i in replacement: if victim.rfind(i) != -1: victim = victim.replace(i,replacement[i]) return victim if __name__ == "__main__": write = False if len(sys.argv) > 1: if sys.argv[1] == r'-w': write = True target = sys.argv[2] else: target = sys.argv[1] try: subject = file(target,"r").read() if write: file(target,"w").write(lamonize(subject)) else: print lamonize(subject) except: print "Sorry, ", target, " does not exist" else: print \ """ sanitize.py, C 2006 Henry Finucane. Usage: sanitize [-w] [target] Where [target] is the plain text file that you want to remove contractions. -w writes to the specified file. Note that this is dangerous and not recommended. By default, we write to stdout. """