31 July
2007

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()

By Gregory Dudek at | Leave a comment |    
Comments
There are no comments.
Trackbacks
Please send trackback to:/blog/70/tbping
There are no trackbacks.
Post your own response

Each comment is manually screened for the presence of appropriate and substantive content, due to a constant onslaught of comment-spam. This means there may be a delay before your comment appears.


(Some kind of name is required, will be visible)

Required, whatever you enter will be visible to other users.


(Optional, used for "mailto" link)

Your email address is not required, but if you insert it it will be displayed so people can contact you.

Answer this question correctly to demonstrate that you are not a dumb spambot.



The title for your comment.



Your comment goes here. All relevant comments are welcome, except for those that simply promote an irrelevant product or else are used to fraudulently inflate the link count to an irrelevant web page. They appear after moderation. Don't forget to also fill in the captcha below or your text will be rejected automatically!

You must answer this question to prove you are human
Which one has ice cream (pick a number 1-5): 1:DairyQueen, 2:KFC, 3:FBI, 4:NFL, 5:NBC-TV?

Answer this question correctly to demonstrate that you are not a dumb spambot.