/
likepython
executable file
·57 lines (48 loc) · 1.55 KB
/
likepython
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
# Author: Jonathan Howard
# Description: OMG! It's like python, but like, totally casual!
import os, sys, re, tokenize
from subprocess import *
def mktest(pattern):
return re.compile(pattern).search
like_python_tokens = [
'omg','so','like','totally','right',
'friggin','fuckin','dude','man','bro','broheim','broseph',
'lol','rofl','teh','ohai','plz','kthx','bai',
'yo','homey','homeboy','sup','dog',
'girl','ma','biatch','ho',
'shit','shiiit',
'wicked','hella','anyways',
'just','hey','yeah','ok',
'um','uh','ah','actually','something',
]
like_python_tests = [
mktest(r'lo+l'), mktest(r'shiii+t'), mktest(r'to+tally'),
]
def handle_input():
if len(sys.argv) == 2:
return sys.argv[1]
else:
print "Usage: likepython path/to/file.lp"
exit()
def main():
# Parse input file for tokens
input_file = handle_input()
file = open(input_file)
tokens = tokenize.generate_tokens(file.readline)
# Remove likepython tokens, leaving valid python temp file behind.
py_tokens = [(type,token) for (type,token, _, _, _) in tokens
if token not in like_python_tokens
and not sum( bool(test(token)) for test in like_python_tests )
]
py = tokenize.untokenize(py_tokens)
output_filename = input_file + ".py"
output_file = open(output_filename, 'w')
output_file.write(py)
output_file.close()
# Run through python and return stdout
call(["python", output_filename])
# Remove temp file
os.remove(output_filename)
if __name__ == "__main__":
main()