#! /usr/bin/python2.6

import os, json, simplejson, datetime, time, urllib, urllib2
from socket import gethostname, gethostbyname

class MiniAkismet:
    def __init__(self, akk=None, aip=None, con=None, usa=None):
    	self.api_konkr_key = akk
    	self.author_ip = aip
    	self.content = con
    	self.user_agent = usa

    def submit_data(self):
		try:
			url = "http://%s.api.konkr.com/isspam" % (self.api_konkr_key)
			headers = {'User-Agent' : self.user_agent}      
			data = {'author_ip': self.author_ip, 'content': self.content}
			data_encode = urllib.urlencode(data)
			req = urllib2.Request(url, data_encode, headers)		
			h = urllib2.urlopen(req)
			resp = h.read()
			msg = resp     
		except: 
			msg = 'Error detect spam'

		print msg

api_konkr_key = '1eee28f67868'
author_ip = gethostbyname(gethostname())
spam = 'Sex viagra porn Sarkozy clocking and enlarge your very little penis'
ham = 'konkr/alpha by Toorop with Protecmail.com, le must du filtrage des spams pour blog et pour email'
user_agent = "Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"  

submit = MiniAkismet(api_konkr_key, author_ip, ham, user_agent)
if submit.submit_data():
	print 'End ham submit'