Vineet Gupta of Daylife was apparently checking out my blog, Earth Community Project yesterday and noticed I'd created a "News Search" box for the site and wanted to know a little about it, and asked if I'd share my experience with the Daylife API here as well.
My blog is generally about promoting social and environmental responsibility. I try to talk about current events from around the world and talk about issues that impact all of us, but there are times when I'm simply too busy to search the web for new information and new topics of discussion. A while back, I wondered to myself if I could find a way to completely automate my blog so that I had to do very little to maintain it. While I was half-heartedly searching for a way to do that, I stumbled across Daylife, and by pure accident saw that there was an API available. Now I'm using the Daylife API in a number of different ways, which I'll detail below.
Keeping in mind my ultimate goal of using the API to reduce the amount of time I spend maintaining my blog, I first ended up creating a number of static pages using a search_getRelatedArticles script but employing a different query for each page. I've currently got a dozen pages of content that are always fresh and up-to-date with the latest news on everything from green tourism to humanitarian relief work to climate change and even green celebrity gossip. The best part is that once I wrote the scripts to connect to the Daylife API, the only work I've had to do on them is play with the layout in my style sheets.
After creating these pages, I actually started reading them myself on a daily basis and realized that I was using them to find topical information and create my own content for
the main page of the site. But I was still spending a lot of time searching for news items and looking for more sources based on what I'd gathered from the scripts I'd already written. That's when I had my lightbulb moment, so to speak.
Rather than go from search site to search site, I decided to use the same basic script I was already using, but "enhance" it a little bit. Within five minutes I turned a static search_getRelatedArticles query to Daylife into an embedded "News Search" box that shows up on every page of my site and sits comfortably above the navigation menu.
Doing this in Drupal, which I use for content management, meant one of two things. I could create an entirely new module, but I really don't have the energy to dig into the Drupal documentation to do that. So instead I did what I'd done before... I created a static page that contained the actual Daylife search script, but I replaced the static query with this...
if (isset($_POST['search'])) {
$query = $_POST['search_string'];
}
else {
$query = '(Hayden AND Panettiere)';
}
From there, I created a new block item in Drupal and added a simple form with a text box and submit button, pointed it to my newly created page, and I've instantly created a user-customizable source of constantly updated content.
From a personal point of view, I love using the Daylife API. One of my next projects is to use the tags I assign to each blog post to search Daylife and return relevant news headlines at the bottom of each blog post. This will be up and running as soon as I dig into the Drupal taxonomy system a little deeper and figure out how to pull the tag data into the query.
I'm also working on a method of using cron, a linux shell script, and curl to log into Drupal as an authenticated user and create front paged open thread posts using the Daylife API automatically, without any intervention from me at all. If I can get that to work, I'll almost have my dream of a totally automated blog.
| Attachment | Size |
|---|---|
| ecproject1.jpg | 49.86 KB |