The is a python COREblog "hook" method to allow me to be notified when comments are addded to the blog. This posting is only relevant to COREBlog users.
The following script sends me email when a comment is added.
This is a script called:
methods/addCommentHook
Takes 1 argument:
d='debug'
--------------
if d == 'debug':
d = {}
d["id"] = 10
d["parent_id"] = 10
d["title"] = "titleDebugString"
d["author"] = "authorDebugString"
d["body"] = "THIS IS A TEST DEBUG MESSAGE CAUSED BY RUNNING THE SCRIPT FOR THE MANAGEMENT INTERFACE"
d["moderated"] = "moderatedDebugString"
d["email"] = "dudek@example.com
d["url"] = "urlDebugString"
try:
mailhost=getattr(context, \
context.superValues('Mail Host')[0].id)
except:
raise AttributeError, "Mail Host object cant be found."
to_addr = "moderator@example.com"
from_addr = "blogScript@"+str(container.REQUEST["SERVER_NAME"])
coreblog = context.superValues('COREBlog')[0]
#print coreblog
#print "Moderation:",coreblog.getProperty("moderate_comment")
if coreblog.getProperty("moderate_comment"):
advice="You need to moderate this comment before it will become visible. Even if you delete it, but sure to hit the status change button."
else:
advice="This comment is already visible now since comment moderation is off."
mMsg = """To: %s
From: %s
Mime-Version: 1.0
Content-Type: text/plain;
A comment was added to the blog just now.
%s
Author : %s
Title : %s
URL : %s
EntryID / Moderate :
http://%s/blog/%s/manage_comments
Body :
%s
""" % (to_addr , from_addr , advice, d["author"] , d["title"] ,\
d["url"] , container.REQUEST["SERVER_NAME"], str(d["parent_id"]) , d["body"])
mTo = to_addr
mFrom = from_addr
mSubj = 'Blog comment added: '+d["title"]
#print mMsg, mTo, mFrom, mSubj
#return printed
try:
mailhost=getattr(context, context.superValues('Mail Host')[0].id)
except:
raise AttributeError, "cant find a Mail Host object"
# encode='base64' for HTML mail.
# Note documentation for simple_send puts body LAST and calls is body, but this works.
# Docs for the send method put it first but call it messageText (this too works below).
mailhost.send(mMsg, mto=mTo, mfrom=mFrom, subject=mSubj)
# only relevant when used for debugging.
return "Mail to",mTo,"sent using",mailhost.getPhysicalPath()


