Random ...
July 2018
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        
Tags ...

python+zope++:: Akizmet - limit the comment spam
Posted at 31.Dec,2005 03:08  Comments 1 / Trackbacks 0 / Like this post!
Technorati tag(s):

Spam crossed the mail boundary some time ago. It's now everywhere. Akismet is a service with a simple API to check whether a comment, or trackback or what ever is either spammy or hammy.

Akismet is a Word Press plugin, but the API has been implemented in python, ruby and java. And one needs a Word Press key to actually use it.

Akizmet is a zope product, tested on Zope-2.8.5, using Five (hopefully correctly :P), and akismet.py.

Installing Akizmet is like installing any other zope product. Untar in INSTANCE_HOME/Products (or your products directory) and restart zope.

For this example, we're going to try and check for spamminess for core blog comments. (I think akizmet can be used in forums, guestbooks, etc; where user feedback is wanted.)

Instantiate an Akizmet in coreblog. name it myk . It requires the word press key and blog url.

Now, we have to short circuit the addComment. Add a Script (Python) with id kizmet_addComment with the following contents:

  1 from DateTime import DateTime
  2 ts=DateTime().millis()
  3 kismet = context.myk
  4 r=context.REQUEST
  5 res = kismet.akizmet_comment_check(r)
  6 if not res:
  7    context.addComment(title=r.form['title'],
  8 else:
  9    kismet.addAkizmetItem(id=str(ts),title='',REQUEST=r)
  10  r.RESPONSE.redirect('/somewhere')

What the script does is this:

  • line 3 will get the akizmet instance
  • line 5 will check the comments posted for spamminess
  • line 6 will check for non spam, and call coreblog's real action (addComment)
  • line 8 if the comments fail the test, we'll add it to our akizmet instance, for verification and submission (as spam or ham) to akismet service.

There should be a better way of doing this, but that's one easy way I could think of. If you have other ideas or implementation, please inform the rest of us.

It'd be even better if we can just have the short circuit script as one of the Akizmet methods. Ideas?

The product is in use here, and for the time being works. Sometimes akismet does miss and I think we need to train akismet more for effective use; that's why there's a form for us to submit to akismet (the service).

The product is still beta, ymmv, zpl, yadda yadda. Please comment and send bugs or ideas.

Get it here


Bookmark and Share

Is this entry helpful? Comments/Donate/Click some google ads.  
Trackback is http://myzope.kedai.com.my/blogs/kedai/61/tbping 

beforeAddComment hook method


It's not documented, but according to the source, COREBlog has a hook that is run before a comment is added. Put a method called "beforeAddComment" in the blog's "methods" folder and it will get called, much like the "addCommentHook" (with a parameter "d").

I'd put this in that script:

ts = DateTime().millis()
kismet = context.myk
res = kismet.akizmet_comment_check(request)
if res:
kismet.addAkizmetItem(id=str(ts), title='',REQUEST=request)
return {'moderated':True}
return False

...but there is a little problem with the handling of REQUEST: addAkizmetItem does a REQUEST.RESPONSE.redirect to manage_main at the end... maybe akizmet_comment_check and addAkizmetItem should be changed to get a dictinary with the coreblog comment parameters instead of REQUEST.

The return value of the hook is a bit special (I think that API wasn't really finished). If the return value is a dictionary that has a key called "moderated" (any value will do), coreblog will moderate the comment. Otherwise the return value should best be False.

But anyway, thank you for a good job!

betabug  at 07.Oct,2007 03:09
Post a comment