def spam_check(content, item_of_interest, request): """ Uses AKISMET to check if comment is spam """ akismet.USERAGENT = "David Lynch's Python library/1.0" my_api_key = settings.AKISMET_KEY try: real_key = akismet.verify_key(my_api_key, "http://www.YouTalkEdu.com") if real_key: is_spam = akismet.comment_check( my_api_key, "http://www.YouTalkEdu.com", request.META['REMOTE_ADDR'], request.META['HTTP_USER_AGENT'], request.META.get('HTTP_REFERER', ''), comment_content=content, comment_auther_email=item_of_interest.user_id.email) if is_spam: return True else: return False except akismet.AkismetError, e: print 'Something went wrong, allowing comment' print e.response, e.statuscode return False
def marked_not_spam(self, comment, request): key = self._get_key() if not key: return try: if verify_key(key, comment.site.domain): data = self._get_data_from_comment(comment) submit_ham(key, comment.site.domain, **data) except AkismetError, e: print e.response, e.statuscode
def isspam(comment, author, ipaddress, agent = defaultagent, apikey = defaultkey): try: valid = akismet.verify_key(apikey, pageurl) if valid: return akismet.comment_check(apikey, pageurl, ipaddress, agent, comment_content = comment, comment_author_email = author, comment_type = "comment") else: print 'Invalid key' return False except akismet.AkismetError, e: print e.response, e.statuscode return False
def isspam(comment,author,ipaddress,agent=defaultagent,apikey=defaultkey): try: valid = akismet.verify_key(apikey,pageurl) if valid: return akismet.comment_check(apikey,pageurl,ipaddress,agent,comment_content=comment,comment_author_email=author,comment_type="comment") else: print ('Invalid key') return False except (akismet.AkismetError) as e: print (akismet.AkismetError) print (e.response, e.statuscode) return False
def isspam(comment, author, ip, agent=defaultagent, apikey=defaultkey): try: valid = akismet.verify_key(apikey, pageurl) if valid: return akismet.comment_check(apikey, pageurl, ip, agent, comment_content=comment, comment_author_email=author, comment_type='email') else: print 'Invalid key' return False except akismet.AkismetError, e: print e.response, e.statuscode return False
def test(): try: real_key = akismet.verify_key(my_api_key, "illustrationarchive.cardiff.ac.uk") print real_key if real_key: is_spam = akismet.comment_check(my_api_key, "illustrationarchive.cardiff.ac.uk", "127.0.0.1", "Mozilla/5.0 (...) Gecko/20051111 Firefox/1.5", comment_content=spam_comment) if is_spam: print "Yup, that's spam alright." else: print "Hooray, your users aren't scum!" except akismet.AkismetError, e: print e.response, e.statuscode
def pre_save_comment(sender, **kargs): if 'instance' in kargs: comment = kargs['instance'] print comment # If in debug mode skip this check with Akismet if not settings.DEBUG: try: real_key = akismet.verify_key(settings.AKISMET_KEY ,Site.objects.get_current().domain) if real_key: is_spam = akismet.comment_check(settings.AKISMET_KEY ,Site.objects.get_current().domain, comment.ip_address, None, comment_content=comment.content) if is_spam: comment.is_public = False print "That was spam" except akismet.AkismetError, e: print e.response, e.statuscode
def akismet_spamcheck(content, remote_addr, user_agent): """Returns True if spam, False if not spam""" try: real_key = akismet.verify_key(settings.AKISMET_APIKEY, \ settings.AKISMET_URL) is_spam = akismet.comment_check(settings.AKISMET_APIKEY, \ settings.AKISMET_URL, remote_addr, user_agent, \ comment_content=content) if is_spam: return True else: return False except akismet.AkismetError, e: logging.error("%s, %s" % (e.response, e.statuscode))
def _submit_comment_to_akismet(self, text, status): """ Submit spam comment to akismet """ site = self.getSitePath() user_agent = self.REQUEST.get('HTTP_USER_AGENT', '') user_ip = self.REQUEST.get('REMOTE_ADDR', '127.0.0.1') text = unidecode(text) if has_api_key and akismet_api_key: if akismet.verify_key(akismet_api_key, site): if status: akismet.submit_spam(akismet_api_key, site, user_ip, user_agent, comment_content=text) else: akismet.submit_ham(akismet_api_key, site, user_ip, user_agent, comment_content=text)
def check_akismet(request, comment): site = request.META.get('HTTP_HOST', settings.WEBSITE_URL) try: real_key = akismet.verify_key(settings.AKISMET_KEY, site) if real_key: is_spam = akismet.comment_check( settings.AKISMET_KEY, site, request.META.get('REMOTE_ADDR', '127.0.0.1'), request.META.get('HTTP_USER_AGENT', 'unknown'), comment_content=comment) if is_spam: return True else: return False except akismet.AkismetError, e: print e.response, e.statuscode
def pre_save_comment(sender, **kargs): """ Run comment through a markdown filter """ if 'comment' in kargs: comment = kargs['comment'] # If in debug mode skip this check with Akismet if not settings.DEBUG: try: real_key = akismet.verify_key(settings.AKISMET_KEY ,Site.objects.get_current().domain) if real_key: is_spam = akismet.comment_check(settings.AKISMET_KEY ,Site.objects.get_current().domain, comment.ip_address, None, comment_content=comment.comment) if is_spam: comment.is_public = False print "That was spam" except akismet.AkismetError, e: print e.response, e.statuscode # Apply markdown comment.comment = markdown(comment.comment)
def _is_spam(self, text): """ Check if user submitted a spam comment. """ site = self.getSitePath() user_agent = self.REQUEST.get('HTTP_USER_AGENT', '') user_ip = self.REQUEST.get('REMOTE_ADDR', '127.0.0.1') text = unidecode(text) is_spam = False if has_api_key: try: akismet_key = akismet.verify_key(akismet_api_key, site) if akismet_key: is_spam = akismet.comment_check(akismet_api_key, site, user_ip, user_agent, comment_content=text) except akismet.AkismetError: pass return is_spam
def check_spam(self, comment, content_object, request): """ Returns True if the comment is spam and False if it's ham. """ key = self._get_key() if not key: # TODO: log a warning return False try: if verify_key(key, comment.site.domain): data = self._get_data_from_comment(comment) data.update({ # not stored on the comment model, have to get them from the request 'referrer': request.META.get('HTTP_REFERER', ''), 'user_agent': request.META.get('HTTP_USER_AGENT', '') }) return comment_check(key, comment.site.domain, **data) except AkismetError, e: # TODO: log a warning with the exception print e.response, e.statuscode
def is_spam(comment_content, author_email, ip_address, user_agent = default_user_agent, api_key = default_api_key): try: is_valid = akismet.verify_key(api_key, page_url) if is_valid: return akismet.comment_check( api_key, page_url, ip_address, user_agent, comment_content = comment_content, comment_auther_email = author_email, comment_type = "comment" ) else: print "Invalid api key" return False except akismet.AkismetError, e: print e.response, e.statuscode return False
def spam_check(content, item_of_interest, request): """ Uses AKISMET to check if comment is spam """ akismet.USERAGENT = "David Lynch's Python library/1.0" my_api_key = settings.AKISMET_KEY try: real_key = akismet.verify_key(my_api_key,"http://www.YouTalkEdu.com") if real_key: is_spam = akismet.comment_check( my_api_key,"http://www.YouTalkEdu.com",request.META['REMOTE_ADDR'], request.META['HTTP_USER_AGENT'], request.META.get('HTTP_REFERER', ''), comment_content=content, comment_auther_email=item_of_interest.user_id.email) if is_spam: return True else: return False except akismet.AkismetError, e: print 'Something went wrong, allowing comment' print e.response, e.statuscode return False
def is_working_akismet_key(key, blog): key = app.config['AKISMET_KEY'] blog = app.config['APPLICATION_URL'] return akismet.verify_key(key=key, blog=blog)