-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspamController.py
56 lines (51 loc) · 2.08 KB
/
spamController.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from akismet import Akismet
import uuid
from secrets import *
def report_as_spam(comment, request):
akismet_api = Akismet(key=Secrets.AKISMET_API_KEY, blog_url="http://www.brianbondy.com/")
if akismet_api.verify_key():
akismet_data = {
'comment_type': 'comment',
# 'referrer': request.META.get('HTTP_REFERRER', ''),
# 'user_ip': request.META.get('REMOTE_ADDR', ''),
# 'user_agent': request.META.get('HTTP_USER_AGENT', ''),
'comment_author': comment.name or '',
'comment_author_email': comment.email or '',
'comment_author_url': comment.homepage or '',
}
akismet_api.submit_spam(comment.body.encode('utf8', 'ignore'), akismet_data, build_data=True)
return True
else:
raise "Invalid Akismet key"
return False
def report_as_good(comment, request):
akismet_api = Akismet(key=Secrets.AKISMET_API_KEY, blog_url="http://www.brianbondy.com/")
if akismet_api.verify_key():
akismet_data = {
'comment_type': 'comment',
# 'referrer': request.META.get('HTTP_REFERRER', ''),
# 'user_ip': request.META.get('REMOTE_ADDR', ''),
# 'user_agent': request.META.get('HTTP_USER_AGENT', ''),
'comment_author': comment.name or '',
'comment_author_email': comment.email or '',
'comment_author_url': comment.homepage or '',
}
akismet_api.submit_ham(comment.body.encode('utf8', 'ignore'), akismet_data, build_data=True)
else:
raise "Invalid Akismet key"
def is_spam(comment, request):
akismet_api = Akismet(key=Secrets.AKISMET_API_KEY, blog_url="http://www.brianbondy.com/")
if akismet_api.verify_key():
akismet_data = {
'comment_type': 'comment',
# 'referrer': request.headers['REFERRER'],
# 'user_ip': request.META.get('REMOTE_ADDR', ''),
# 'user_agent': request.headers['USER_AGENT', ''],
'comment_author': comment.name or '',
'comment_author_email': comment.email or '',
'comment_author_url': comment.homepage or '',
}
if akismet_api.comment_check(comment.body.encode('utf8', 'ignore'), akismet_data, build_data=True):
return True
else:
return False