Report abuse

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
#!/usr/bin/python -S

import re
import sys
from os import environ as env
sys.path.insert(0, env["TM_SUPPORT_PATH"] + "/lib")

import webpreview

content = sys.stdin.read()

if "TM_SWEAR_WORDS" in env:
    swear_words = env["TM_SWEAR_WORDS"].split(":")
else:
    swear_words = ["foo", "bar", "baz"]
swear_counts = {}

for word in swear_words:
    matches = re.findall(r"%s" % word, content, re.M)
    print matches
    swear_counts[word] = len(matches)

print webpreview.html_header("SwearCount", "")
print "<table>"
for word in swear_counts.keys():
    print "<tr><td>%s</td><td>%i</td></tr>" % (word, swear_counts[word])
print "</table>"    
print webpreview.html_footer()