Akismet Webservice

 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
32
33
34
35
36
37
38
39
40
41
import urllib, urllib2


AKISMET_URL = 'rest.akismet.com/1.1'
USER_AGENT = 'askimet.py/0.0'


class Akismet(object):
    def __init__(self, api_key, blog):
        self.api_key = api_key
        self.blog = blog
        self.service = 'http://%s.%s' % (self.api_key, AKISMET_URL)

    def verify_key(self):
        return urllib2.urlopen(
            urllib2.Request(
                'http://%s/verify-key' % AKISMET_URL,
                urllib.urlencode({'key': self.api_key, 'blog': self.blog}),
                {'User-Agent': USER_AGENT}
            )
        ).read() == 'valid'

    def _get_url_data(self, method, comment_data):
        comment = {'blog': self.blog, 'comment_type': 'comment'}
        comment.update(comment_data)

        data = urllib2.urlopen(
            urllib2.Request(
                '%s/%s' % (self.service, method),
                urllib.urlencode(comment),
                {'User-Agent': USER_AGENT}
            )
        ).read()
        if data not in ('true', 'false'):
            raise Exception(data)
        return data == 'true'

    def __getattr__(self, name):
        def f(**kwargs):
            return self._get_url_data(name.replace('_', '-'), kwargs)
        return f

More like this

  1. Using Akismet/TypePad AntiSpam with Django's new comments framework by sciyoshi 4 years, 9 months ago
  2. Prevent Django newcomments spam with Akismet (reloaded) by sciyoshi 3 years, 10 months ago
  3. Unobtrusive comment moderation by ubernostrum 6 years, 2 months ago
  4. Django Akismet by yeago 4 years, 5 months ago
  5. Clean spam from comments by running management command and akismet by iElectric 7 months, 1 week ago

Comments

(Forgotten your password?)