Akismet.py
December 2, 2005
Akismet is the hot new spam-detector by the same people who brought you WordPress. In fact, it’s so hot and new that the only real way I’ve seen so far to interact with it has been the official plugin (in PHP) for WordPress.
Since the first draft of the API documentation was released earlier today, I thought I’d write up a quick Python module that will talk to it.
It’s a very light wrapper around the API’s functionality. I didn’t want to do anything fancy with this, so I didn’t bother with classes or the like.
To use it, put akismet.py somewhere where Python will see it. The do something like this: (akismet_example.py)
—–
import akismet
akismet.USERAGENT = "MyApplication/MyVersion"
my_api_key = "SOMETHING"
try:
real_key = akismet.verify_key(my_api_key,"http://www.example.com")
if real_key:
is_spam = akismet.comment_check(my_api_key,"http://www.example.com",
"127.0.0.1", "Mozilla/5.0 (...) Gecko/20051111 Firefox/1.5",
comment_content="VIAGRA! LOTS OF VIAGRA!")
if is_spam:
print "Yup, that's spam alright."
else:
print "Hooray, your users aren't scum!"
except akismet.AkismetError, e:
print e.response, e.statuscode
# If you're a good person, you can report false positives via
# akismet.submit_ham(), and false negatives via akismet.submit_spam(),
# using exactly the same parameters as akismet.comment_check().
—–
I’m not 100% sure of the pure Pythonic nature of the way I’m handling arguments… but it does seem to work.
Download: Akismet.py - Akismet_example.py
Note: To use it you’ll need a valid WordPress.com API key. Which is easy to get — you just just have to join WordPress.com, and you’ll find it in your admin interface, in the “Users” section.
Update: Fuzzyman has written another Python module to access Akismet, taking a more class-oriented approach than mine. So if you hate the minimalist implementation here… there is an alternative! (Okay, it’s not really minimalist — anything which defines Exceptions can’t be called minimalist, to my mind.)
December 2, 2005 at 9:30 am
[...] has written a cool library for using the Akismet API in Python. I expect over the holidays a few more implementations will come out as people have a little more time for hacking on fun projects. We’ve had a few more development rumblings on the spam-stopper mailing list, so if you have something finished be sure to let me know and I’ll be happy to blog about it. [...]
December 2, 2005 at 3:14 pm
[...] Akismet ã‚’ WordPress 以外ã?‹ã‚‰ä½¿ã?†è©±ã?¯å®Œå…¨ã?« Valid ã?®ã‚ˆã?†ã?§ã?™ã€‚Python ã?‹ã‚‰å‘¼ã?³å‡ºã?™æ–¹æ³•ã?Œ kemayo.wordpress.comã?§è§£èª¬ã?•れã?¦ã?„ã?¦ã€?ã?•らã?«ã??れを Matt 自身も紹介ã?—ã?¦ã?¾ã?—ã?Ÿã€‚ [...]
December 25, 2006 at 3:52 pm
aaaaaaaaaaaaaaaaaaaaaa
March 5, 2007 at 1:36 am
[...] David Lynch’s Python library [...]
September 29, 2007 at 6:58 pm
How can I get “Akismet.py”? I click on the link and nothing happens.
November 30, 2007 at 8:18 pm
[...] pm, December 1st, 2005 David Lynch has written a cool library for using the Akismet API in Python. I expect over the holidays a few more implementations will come out as people have a little more [...]
November 30, 2007 at 10:41 pm
hsoulard: Sorry, I didn’t check my moderation queue for some time. The server I had the files parked on apparently went down for a week or two around when you asked your question, so I moved everything to Google Code.
December 20, 2007 at 9:34 am
[...] David Lynch’s Python library [...]