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

Posted by dudek at July 31 11:56 | Leave a comment | permalink link to this entry |
Comments
There are no comments.
Trackbacks
Please send trackback to:/blog/70/tbping
There are no trackbacks.
Post your own response


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


(Optional, will appear as a link)

Leave an URL if you want to provide a relevant link that relates to your comment or identifies you.



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.

You must answer this question to prove you are human
what is 5 plus 1?

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







Science Blogs - Blog Top Sites Science Blogs - Blog Catalog Blog Directory Science Blogs - Blog Top Sites Science Blogs - Blog Catalog Blog Directory