For awhile now I've been trying to come up with a good way to inspire me to write more about current topics. The reason I had wanted to be inspired more, beyond the general want to think about things more, was so I could reach a goal of publishing one blog post a week. Since I want these blog posts to be relatively centered on thoughts I've had throughout the week, I figure if automatically I email myself a list of urls and the thoughts I had on them, hopefully I can come up with a decent blog post.
So I wrote a little Bash script to run every Saturday morning and email me the summary of my week, according to delicious. I will spend the rest of this article explaining on how it works. If you would like, you can just look at the source, located at my GitHub.
I'm not going to tell you how to write bash scripts here, there are many TLDPs on that subject (see the reference section). But I will do a quick walk-through.
The first few lines figure out the parameters we will be passing to the delicious.com API, mainly the dates we want, and the specific format those dates must be in.
After that we define the API URL that we will be getting and put the date parameters into the proper format.
Then we make sure you've passed in the proper parameters. If you haven't we display an error, else we put all of the URL parts together.
Finally we print out some info, and use curl to pull the data from the URL we constructed. Note the -s on curl. This is important so we don't get garbage filling our script about how long it took to pull down the script.
At the very end we take what we curl'd and pass it through an XSLT processor to give us a nice format and print this out. We could have just printed out the XML, but that is kind of a pain to read normally.
I found writing XSLT files a pain. But basically this is how they work. First you define that this is a XSLT file.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://exslt.org/strings" extension-element-prefixes="str" exclude-result-prefixes="str" >
Then you need to define how to turn the XML into plain text (or what ever format of text you want...). Note how we do matching in a similar structure to the actual XML.
<xsl:output method="html" /> <xsl:template match="post"> <xsl:text> ----------- </xsl:text> Title: <xsl:value-of select="@description" /> <xsl:if test="@extended"> Description: <xsl:value-of select="@extended" /> </xsl:if> URL: <xsl:value-of select="@href" /> When: <xsl:value-of select="@time" /> </xsl:template>
The following is the cron command I have set up.
42 7 6 re-delicious.sh uname pwd | mail -s "Links" email@example.com
It's very possible that it would be easier to write this in another language or something, but It ended up being a fun little script. The main advantage you would gain by writing it in another language is having a good XML parser, so you could skip using XSLT to parse your XML file.
Anyway, hope you found this interesting.