Skip to content

Instantly share code, notes, and snippets.

@terapyon
Last active December 14, 2015 20:09
Show Gist options
  • Save terapyon/5142181 to your computer and use it in GitHub Desktop.
Save terapyon/5142181 to your computer and use it in GitHub Desktop.
#! ~/dev/misc/tokyoci/py/bin/python
# coding: utf-8
from akismet import Akismet
KEY = "xxxxxxxxxx"
BLOG_URL = "http://www.cmscom.jp/blog"
def _to_str(s):
assert isinstance(s, basestring)
if not isinstance(s, str):
s = s.encode('utf-8')
return s
def _to_unicode(s):
assert isinstance(s, basestring)
if not isinstance(s, unicode):
s = s.decode('utf-8')
return s
def chk_key():
key = KEY
blog_url = BLOG_URL
api = Akismet(key=key, blog_url=blog_url, agent='Example/0.1')
return api.verify_key()
def main(s):
key = KEY
blog_url = BLOG_URL
api = Akismet(key=key, blog_url=blog_url, agent='Example/0.1')
data = {'user_ip': '192.168.0.1',
'user_agent': "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)"}
return api.comment_check(_to_str(s), data=data)
if __name__ == "__main__":
print "Check key: ", chk_key()
s = u"terada"
print "Check Spam: ", main(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment