5
# Copyright Michael Foord 2005
7
# Test CGI for akismet.py - the Python interface to the akismet API
9
# http://www.voidspace.org.uk/python/modules.shtml
12
# Released subject to the BSD License
13
# Please see http://www.voidspace.org.uk/python/license.shtml
15
# For information about bugfixes, updates and support, please join the Pythonutils mailing list.
16
# http://groups.google.com/group/pythonutils/
17
# Comments, suggestions and bug reports welcome.
18
# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml
19
# E-mail fuzzyman@voidspace.org.uk
22
A simple test CGI for akismet.py
24
Requires cgiutils and a file called apikey.txt
33
sys.path.append('../modules')
34
sys.path.append('modules')
36
from cgiutils import *
38
from akismet import Akismet
44
valuelist = ['comment', 'comment_author_email', 'comment_author',
45
'comment_author_url', ]
47
header = '''<html><head><title>Akismet Test CGI</title></head><body>
48
<center><h1>Testing the Python Interface to Akismet</h1>
50
<em><a href="http://www.voidspace.org.uk/python/index.shtml">Fuzzyman</a></em>
52
<h2>Combatting Comment Spam</h2>
53
<h2>Akismet Test Version %s</h2>
54
<a href="http://www.voidspace.org.uk/python/modules.shtml#akismet">
55
<h2>Python API Version %s</h2></a>
56
''' % (__version__, akismet.__version__)
60
<em>Posts With the Name set as </em><strong>viagra-test-123</strong>
61
<em>Should Always be Marked as Spam</em><br>
62
<strong>Enter a comment to test :</strong>
63
<form method="post" action="**scriptname**">
65
<tr><td align="right"><small><strong><label for="comment_author">Your Name:</label></strong></small></td>
66
<td><input type="text" name="comment_author" value ="**comment_author**" ></td></tr>
67
<tr><td align="right"><small><strong><label for="comment_author_email">Your E-Mail Address:</label></strong></small></td>
68
<td><input type="text" name="comment_author_email" size="40" value="**comment_author_email**" ></td></tr>
70
<tr><td align="right"><small><strong><label for="comment_author_url">Homepage:</label></strong></small></td>
71
<td><input type="text" name="comment_author_url" value="**comment_author_url**" size="40"></td></tr>
73
<small><strong><label for="comment">Please make your comments below</label></strong></small><br>
74
<textarea name="comment" cols="60" rows="6" wrap="hard">**comment**</textarea>
76
<input type="submit" value="Go For It"><input type="reset">
80
footer = '</center></body></html>'
82
no_key = '''<h1>This script needs a %sWordpress API Key</h1>
83
<h2><a href="http://wordpress.com">Vist Wordpress</a></h2>
86
res_line = '<h1>Akismet Says the Comment is %s</h1>'
90
# FIXME: could break here if apikey.txt exists, but has no key/blog_url
95
if not api.verify_key():
97
return no_key % 'Valid '
98
# check the form - it contains some relevant data
99
# the rest will be filled in with defaults
100
for entry, val in os.environ.items():
101
if entry.startswith('HTTP'):
103
result = api.comment_check(req['comment'], req, DEBUG=DEBUG)
105
return res_line % result
107
return res_line % 'Spam'
109
return res_line % 'Ham'
112
# getrequest, serverline, cgiprint, replace - all come from cgituils
113
req = getrequest(valuelist)
118
if req['comment'].strip():
119
result = '<br><br>%s<br><br>' % results(req)
121
req['comment_author'] = 'viagra-test-123'
123
rep = {'**result**': result }
124
for key, val in req.items():
125
rep['**%s**' % key] = val.strip()
126
rep['**scriptname**'] = os.environ['SCRIPT_NAME']
127
print replace(form, rep)
131
if __name__ == '__main__':
132
if not 'SCRIPT_NAME' in os.environ:
133
print 'This script must be run as a CGI'
142
2005/12/05 Version 0.1.2
143
-----------------------------
148
2005/12/04 Version 0.1.1
149
-----------------------------
151
Added the version numbers
153
Added default name 'viagra-test-123'
156
2005/12/02 Version 0.1.0
157
-----------------------------
159
A simple test script for akismet.py
161
It tests ``verify_key`` and ``comment_check`` in 80 lines of code
b'\\ No newline at end of file'