PyProfanity is a small program I whipped up to be used by a clients guest book posting routine. The whole point is a simply way to prevent guests and spammers alike from posting profanity and sexually explicit content in their messages. I have set up a simple cherrypy app here to allow people to try it out and help me add to the wordlist. I have access to a log that lets me see everything tried so I can see how effective it is. Anyone is welcome to test. The code is simple enough to post directly on here so here it is.
import re
class ProfanityFilter: def readProfanities(): profanities = [] file = open('wordlist','r') for line in file: line = line.strip('\n') profanities.append(line) return profanities profanities = readProfanities() def replaceProfanity( self, query ): for w, profanity in enumerate( self.profanities ): replacement = '' for c in range(len(profanity)): replacement = replacement + '*' p = re.compile(profanity , re.I) query = p.sub(replacement, query) return query
For obvious reasons I am not going to post contents of 'wordlist'. If you would like a copy of it send me an email.
Suggestion and improvements are welcome.



