Posts Tagged ‘mollom’

Moving hMollom to a monadic base

Monday, April 12th, 2010

In a move to finally grok monads and monad stack a bit better, I decided to move the hMollom code to a monad based implementation. The exported functions now execute in the MollomMonad, which at this point is defined as follows:


type MollomState = ReaderT MollomConfiguration (StateT MollomServerList IO)
type MollomMonad = ErrorT MollomError (StateT (Maybe SessionID) MollomState)

The main concept of the code remains the same, each exported function calls the service function. The latter returns a MollomState a, to capture the fact that during the Mollom request, we potentially need to update the list of servers we can query with API calls. This result is then lifted into the MollomMonad stack by using the following function.


returnStateT a = StateT $ \s -> liftM (flip (,) s) a

This is illustrated in the following control flow figure (for a full sized image, follow the link to flickr):

Control flow in hMollom

The error handling is done by usage of the ErrorT monad transformer, which add the possibility to return a Left MollomError as function value, indicating a fault during the handling of the request. At this point, I have not added a decent runMollomMonad function, as I am still pondering which functions may be most useful for the users of this library. However, you can easily employ the following function, where defaultMollomConfiguration :: MollomConfiguration and we start without any servers that are available.


(\m -> (runStateT $ (runReaderT $ (runStateT . runErrorT $ m) (Nothing) ) defaultMollomConfig) UninitialisedServerList)

As usual, the code is available from both the GitHub repository, as well as from Hackage. All feedback is welcome. Thanks to #haskell and #ghentfpg for bearing with my questions.

hMollom

Friday, February 26th, 2010

You may or may not be aware of the excellent anti-spam service provided by Mollom, founded by two friends and colleagues, Dries Buytaert and Benjamin Schrauwen. Mollom provides an API to program against, allowing support libraries to be written in a variety of languages and for numerous platforms. Top-notch examples are the Drupal plugin (obviously :-) and the WordPress plugin. Next to that there are a number of libraries for Java, PHP5, Ruby, Python, etc. Sadly, a Haskell library was lacking.

Given that I enjoy programming in Haskell and need to sharpen my Haskell-fu, I set out to write a library for interfacing with the Mollom API. The library is far from finished, but it is functional at this point, so if you have Mollom keys, you can call the services and fight the spam war on your Haskell driven website.

I maintain two repositories where you can get the library:

At this point the library has been given version 0.1. So it is still lacking quite a lot of features. Stuff that is on the immediate TODO list:

  • Add fault handling
  • Add server list refreshing
  • Encapsulate the state in a monad

Any feedback is appreciated.

PyMollom moved to GitHub

Monday, February 8th, 2010

Just a quick update. I have moved the repository for PyMollom over to GitHub. If you are unfamiliar with git, you can check out the library using git clone git://github.com/itkovian/PyMollom.git. At this point, the library is still the same, but I do plan on integrating the new language detection ASAP.

Haskell wraper for Mollom

Sunday, October 5th, 2008

I have been a Haskell fan since I first get introduced to the language, in the now deprecated course taught by Koen De Bosschere when I took my final year before graduating as a licentiate in computer science (which would now be a MsC. in CS). Due to a lack of time, mostly, I never proceeded very far beyond the basics, not even when I was a teaching assistant for this course. Still, with Mollom having been released, the Haskell application database Hackage finally coming into adulthood, or some form of it, I deemed the time ripe to attempt writing a wrapper for Mollom.

That said, first thing to do is check Hackage and find stuff we can reuse. haxr immediately comes to mind for the XMLRPC stuff. Other packages I am using are base64-string, crypto, configfile,
Installing the above will download and install a number of other libraries on which these depend. Still, Hackage seems to do the trick just fine, installing everything I needed.

Mollom updated to reflect API document changes

Wednesday, September 17th, 2008

As you may be aware of, the Mollom API has undergone some small changes in order to better deal with load balancing. A side effect of this is that the Python module I wrote and maintain had to be updated as well. Meanwhile, I uncovered a few bugs, the most important of which resulted in the inability to handle empty server lists provided by the Mollom service. As far as use of the module is concerned, there are not really any changes, except one. The MollomBase class now provides a non-empty method that implements a basic callback cache strategy for the server list.

You can find the tarball containing the modules and the darcs repository here. To pull from the darcs repository, use darcs get http://itkovian.net/darcs/python_mollom.

Mollom T-shirt

Friday, August 8th, 2008

Dries and Ben (of Mollom fame) mailed out a number of t-shirts to people who made a contribution to their service. I wrote a Python wrapper around the Mollom API. So, thanks guys, I will wear it with pride ;-)

Python wrapper for Mollom

Thursday, May 8th, 2008

With the release of the Mollom API, I have cleaned up and documented my Python wrapper for the API.

You can get the code from the darcs repository at http://itkovian.net/darcs/python_mollom. Alternatively, a packed tarball is also available.

For the moment, the repository contains two files Mollom.py and HTTPTransport.py. The former contains the MollomAPI and MollomFault classes. The latter contains a derived class to deal with HTTP transport in the XML PRC library, as the default Python code does not seem to do things correctly. To get the response from the Mollom service as a Python dictionary, you need to either use the provided HTTPTransport class or provide your own implementation

To deal with caching and using session IDs a MollomBase class is present, which can be overridden to allow a user defined caching mechanism for the server list to be used. This class is still under heavy development, so it is prone to (frequent) changes.

MollomAPI offers the following methods:

  • getServerList
  • checkContent
  • sendFeedback
  • getImageCaptcha
  • getAudioCaptcha
  • checkCaptcha
  • getStatistics
  • verifyKey

I plan to see if I can get this into Django as well as a contributed app that can be included in a Django project.

Update (2008/09/18) I have incorporated the changes made to the API document on 2008/09/10. The version of the tarball has been bumped to 0.2. Additionally some bugs were fixed, so you might want to update to this version rather than sticking with the old one.

Update (2010/02/08) I have moved the code to a new repository at GitHub. Get the library using git clone git://github.com/itkovian/PyMollom.git. For now, I do plan on keeping the darcs repo hosted at my website and the github repo in sync, so you can pull from either.

SPAM, begone!

Tuesday, April 1st, 2008

As you probably know, the moment a website becomes available on the web, it does not take long before spammers locate it, and try to pollute your content. I have no need for viagra, penis enlargement, large amount of money that can easily be transferred to my bank account, etc. and I have no desire whatsoever to offer these people another forum to offer their (illegal) merchandise. So, task one was to find adequate means for protecting myself, and (the few) people who read my rants.

Luckily, in the past, I have shared an office with Dries who has been thinking hard on the spam problem and has been working on a solution since he completed his PhD. The goal was to provide not simply spam protection, but also to help people increase the quality of the content, by protecting against profanities, anonymous user registration etc. To shorten a long story, this website has been using Mollom as its spam protection mechanism since its inception. As you can see, Mollom has been quite effective, I’ve only had five (iirc) false negatives (spam that was classified as acceptable content), which is almost perfect.

Mollom kills spam

Thanks guys, you rock!