Created
May 24, 2009 01:43
-
-
Save jcsalterego/116908 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env python | |
| # | |
| """ | |
| $ ./transmorgify.py | |
| input: http://yahoo.com www.blah.com 13 monkey's @username blah | |
| output: ['monkeys', 'blah'] | |
| input: Super impressive http://tr.im/lWb7 (via @jcsalterego) | |
| output: ['Super', 'impressive', 'via'] | |
| input: | |
| output: [] | |
| """ | |
| import re | |
| import sys | |
| inputs = ("http://yahoo.com www.blah.com 13 monkey's @username blah", | |
| "Super impressive http://tr.im/lWb7 (via @jcsalterego)", | |
| "") | |
| # remove digits, @words, urls, remove all the 's, & turn into an array? | |
| def transmorgify(input): | |
| destroy = ('0-9', '\'', '(', ')') | |
| destroy_re = re.compile("[%s]" % "".join(destroy)) | |
| fails = ('@', 'http://', 'www\.') | |
| fails_re = re.compile("|".join(fails)) | |
| print("input: %s" % input) | |
| output = destroy_re.sub("", input) | |
| output = [word for word in output.split(" ") | |
| if word and not fails_re.match(word)] | |
| print("output: %s" % output) | |
| def main(): | |
| for input in inputs: | |
| transmorgify(input) | |
| if __name__ == '__main__': | |
| sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment