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.pyAkismet_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.)

15 Responses to “Akismet.py”

  1. « Akismet Says:

    […] 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. […]


  2. […] Akismet を WordPress 以外?ら使?話?完全? Valid ?よ???。Python ?ら呼?出?方法? kemayo.wordpress.com?解説?れ?????ら???れを Matt 自身も紹介?????。 […]

  3. sharedpile Says:

    aaaaaaaaaaaaaaaaaaaaaa


  4. […] David Lynch’s Python library […]

  5. hsoulard Says:

    How can I get “Akismet.py”? I click on the link and nothing happens.


  6. […] 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 […]

  7. kemayo Says:

    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.


  8. […] David Lynch’s Python library […]


  9. […] статьи на анализ на сервер Akismet’а делается с помощью библиотеки Дэвида Линча, выбранной наугад из двух питоньих библиотек на сайте. […]

  10. sean Says:

    I get “Yup, that’s spam alright.” every time. No matter what text I submit. ?!?! :-(

  11. Luca Says:

    I also get “Yup, that’s spam alright.” every time. No matter what text I submit.


  12. it should also have an ip blocker of some sort, a 24h ban. keep it up.

  13. valashiya Says:

    Thanks for this sample code, I have downloaded it and will study it to see how to write a module to interact with Akismet.

    Nice code BTW


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: