Defensio SPAM 偵測

今天玩了一下 Defensio 的 API, 用來偵測 SPAM 文件跟留言, 官方提供的 python library 也挺方便易用的, 也有提供 async 跟 async_callback。

from defensio import Defensio

api = Defensio(DEFENSIO_API_KEY)  
doc = {  
    'type': 'article',
    'platform': 'streetvoice',
    'title': title,
    'content': content,
    'author-ip': request.META['REMOTE_ADDR'],
    'author-name': username,
    'author-email': email,
    'referrer': request.META['HTTP_REFERER'],
}

status_code, response = api.post_document(doc)  
if status_code == 200:  
    classification = response['defensio-result']['classification']
    if classification == 'spam':
        print "You got SPAM"

目前 Defensio 免費的帳號可以每個月有 25000 次的 quota, 所以只能稍作測試一下, 目前偵測了幾個小時的部落格文章, 超準的ㄝ!

不過在玩 Defensio 之前有先玩了 Akismet, 也挺簡單的。

from akismet import Akismet

spam_data = {  
    'user_ip': request.META['REMOTE_ADDR'],
    'user_agent': request.META['HTTP_USER_AGENT'],
    'referrer': request.META.get('HTTP_REFERRER', 'unknown'),
    'comment_author': username,
    'comment_author_email': email,
}

api = Akismet(AKISMET_API_KEY)  
if api.comment_check(comment, spam_data):  
    print 'is spam'
else:  
    print 'not spam'

不管是 Defensio 跟 Akismet 都有很簡單易用的 Python library 可以用, 只是 Defense 的價格好貴阿!

tzangms

Read more posts by this author.

Subscribe to Oceanic / 海海人生

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!