#!/usr/bin/env python # -*- coding: utf-8 -*- from akismet import Akismet from django.core.management.base import BaseCommand from django.conf import settings from django.contrib.sites.models import Site from django.contrib.comments.models import Comment class Command(BaseCommand): args = " in format dd.mm.yyyy" help = "Sends daily email repot about intranet changes" def handle(self, *args, **options): akismet = Akismet(key=settings.SPAMINSPECTOR_AKISMET_KEY, blog_url="http://%s/" % Site.objects.get(pk=settings.SITE_ID).domain) if not akismet.verify_key(): raise ValueError('no key set') for comment in Comment.objects.all(): data = { 'user_ip': comment.ip_address, 'user_agent': '', 'referrer': '', 'comment_type': 'comment', 'comment_author': comment.user_name.encode('utf-8'), 'comment_email': comment.user_email.encode('utf-8'), 'comment_url': comment.user_url.encode('utf-8'), } if akismet.comment_check(comment.comment.encode('utf-8'), data, build_data=True): comment.delete()