-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathakismettest.py
31 lines (25 loc) · 1 KB
/
akismettest.py
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
import akismet
defaultkey = '09d55c02ef86'
#pageurl = 'http://amnoid.de'
pageurl = 'http://groups.google.com'
#defaultagent = 'akismettest python script from the Collective Intelligence book'
defaultagent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) '
defaultagent += 'AppleWebKit/525.27.1 (KHTML, like Gecko) '
defaultagent += 'Version/3.2.1 Safari/525.27.1'
def isspam(comment, author, ip, agent=defaultagent, apikey=defaultkey):
try:
valid = akismet.verify_key(apikey, pageurl)
if valid:
return akismet.comment_check(apikey, pageurl, ip, agent,
comment_content=comment, comment_author_email=author,
comment_type='email')
else:
print 'Invalid key'
return False
except akismet.AkismetError, e:
print e.response, e.statuscode
return False
if __name__ == '__main__':
print isspam('Buy Viagra!', '[email protected]', '127.0.0.1')
print isspam("That's an interesting post. My vote goes to the green one",
'[email protected]', '67.218.106.36')