published: August 6th, 2009, 11:06 pm, PST
revision: August 21st, 2009, 9:35 pm, PST
topics: bash, makefile, projects, python, rss, wordpress
RSS Email Notifications for WordPress
Introduction
I share a group blog at waterblogged.net with a couple friends. I wanted to get regular email notifications containing complete content for new entries and comments, even for password protected feeds. Some email clients provide varying support for RSS feeds, but I’m a Gmail user and at present this support is very limited. So, I wrote a couple scripts that run on my web server. This documents makes a couple notes and provides links to the source.
As a disclaimer, a big goal of this project was experimentation. The other part being that the end product work specifically for my configuration, in particular, a WordPress blog. Areas of my scripts drift between wildly impractical to very hackish. There were many solutions to this problem and I’m certain what I present is not ideal.
mr_wb.mk – master script
This makefile wraps all operations in one. In retrospect, I think it would be better to have written this in Python, but I also wanted to experiment. Assume spaces are tabs as appropriate when copying snippets or grab the original source.
This useful snippet from the GNU Make manual provides fast PATH searching:
path_search = \ $(firstword $(wildcard $(addsuffix /$(strip $(1)),$(subst :,$(space),$(PATH)))))
Here I experiment with makefile error handling which is basically BASH error handling. I force immediate trap on commands returning non-zero status and print some info.
red := '\e[1;31m'
colorless := '\e[0m'
begin_rule = \
set -e; \
set -o pipefail; \
function err_trap() \
{ \
echo "error: $$BASH_COMMAND returned $$1 at time $(exec_date)."; \
}; \
trap 'err_trap $$?;' ERR; \
echo -e $(red)--- rule: $@ ---$(colorless)
end_rule := \
echo --- done ---
format_feed.py – new feed item to HTML email
This script uses Universal Feed Parser to parse a downloaded comment or entry feed. If new items are found since last execution, they are extracted and converted to a rich text HTML file.
print_missing_modules.py – Python prerequisite checking
This is one of those wildly impractical parts of the script I mentioned I was experimenting with earlier. I ended up canning this feature since the modulefinder module prints a ton of missing modules but most scripts usually run anyway.
cron – regular script execution
Nothing special going on here for cron junkies, but this was my first time, actually, so I’ll explain it in brief. Cron provides for regular execution of arbitrary scripts. A tab delimited format describes regularity and command. For further information, Wikipeda has a nice article. In my case, my cron script looks something like:
*/9 * * * * make -C scripts/mr_wb -f mr_wb.mk -rR --warn-undefined-variables;
Please imagine the spaces surrounding the asterisks as tabs. This script causes Make to be invoked every 9 minutes of every hour. I launch the Cron service by typing crontab .crontab (this script being named .crontab).
Download the file archive here.



