Archive for March, 2009
Exploring CouchDB
In this developerWorks article, I explore the concepts behind Apache CouchDB – an open source, document-oriented database management system. CouchDB uses a RESTful JSON API and JavaScript views to interact with and report on the data stored in the database. Unlike the relational model, the model CouchDB is built on is designed specifically for use in document-oriented web applications such as blogs, wikis and discussion forums. This makes it an exciting prospect as a potential de-facto database for publishing-oriented web applications. The following is the abstract from IBM developerWorks:
Relational databases define a strict structure and provide a rigid way to maintain data for a software application. Apache’s open source CouchDB offers a new method of storing data, in what is referred to as a schema-free document-oriented database model. Instead of the highly structured data storage of a relational model, CouchDB stores data in a semi-structured fashion, using a JavaScript-based view model for generating structured aggregation and report results from these semi-structured documents. CouchDB has been developed from the ground up with Web applications as the primary focus and has its sights on becoming the de-facto database for Web application development.
Read the article in full at http://www.ibm.com/developerworks/opensource/library/os-couchdb/
Utilizing Web 2.0 in Business
Back in February an article I wrote, “Implementing Enterprise 2.0″ was published on IBM developerWorks (read the blog entry about this article here). Around the same time as I wrote this piece I also wrote a piece titled “Utilizing Web 2.0 in Business”. This article was published on developerWorks today – and here is the abstract:
While Web 2.0 has been a huge hit with consumers, some businesses have been much slower to embrace it. Many companies, however, are now realizing the great potential of Web 2.0 and how Web 2.0 services such as YouTube, Twitter, and SlideShare can provide value to their organizations. See how businesses can exploit the power of Web 2.0 services while simultaneously improving workplace relationships. Empower your employees to share information that helps generate sales leads, aids in recruitment, and assists in strengthening your company’s brand, image, and corporate identity. Explore business-oriented Web 2.0 tools such as LinkedIn and CrunchBase and the Web services and APIs that many of these tools offer, allowing their benefits to be incorporated into other applications.
Read the tutorial at http://www.ibm.com/developerworks/web/library/wa-web20business/
Schedule Twitter Posts
Many people (myself included) often post an update to Twitter when publishing a new blog post. WordPress (the blog software I use) and most other blogging platforms include a nice feature that allows you to schedule blog posts to be published at a particular date/time. Wouldn’t it be great if we could also schedule our tweets so that they are posted when our blog post is published? There are countless other potential uses for scheduled tweets. Maybe you’re launching a new product and want to announce it on Twitter on Monday morning at 9am, but are afraid you’ll get caught up on something else – set an automated Tweet and away you go.
Before I begin, I’ll start off by saying that this is a very simple example of scheduling tweets. It will give you a very simple introduction to the Twitter API, the curl tool and the Windows Task Scheduler. There is no pretty graphical user interface, and configuring your scheduled tweets is fairly manual to say the least. If you would like more features, why not incorporate them into your own little application? I’m certainly thinking of doing so. Also – I believe there is a WordPress plugin that will post a tweet when your blog post is published – if this fits your needs, great! Again – this is merely a simple example of what you can do with the Twitter API, it’s not intended to be the holy grail solution for scheduling tweets!
For the sake of this tutorial I am going to assume you’re using the Windows operating system. If you’re using Mac OS, Linux or another Unix variant, the technique used in this tutorial could be easily amended to work with cron. If enough people demand a Mac/Linux version of this tutorial, I’ll write one.
The first thing you’re going to need to do is download cURL. This command-line utility allows you to transfer files over a host of internet protocols, and is perfect for interacting with the Twitter API. It is free and open source, and is available for a wide range of platforms. Visit the cURL download page and download the No-SSL version provided by Daniel Stenburg. At the time of writing, the latest version available was 7.19.4. Once you have downloaded the ZIP file, extract the contents to c:\curl. If you need an archiving utility, download the excellent 7-Zip. That’s all there is to installing cURL! To test it out, open a command prompt (Start->Programs->Accessories->Command Prompt) and change to the curl directory (cd \curl). Enter the following command:
curl http://www.google.ie
Listing 1 – cURL’ing Google.ie
This should spit back a ream of continuous HTML code. This is the HTML source for the Google.ie home page. What you see should be similar to the screenshot below:
Now that we have verified that cURL is working, let’s see how we can use it to interact with the Twitter API. The Twitter API is what is known as a RESTful web service, meaning that it can be queryed using a URI, and will return data in a particular MIME type. Twitter can return data in the XML, JSON, RSS or Atom MIME types. Let’s start working with Twitter by retrieving the Public Timeline in RSS format. In your command prompt, issue the following command:
curl http://twitter.com/statuses/public_timeline.rss
Listing 2 – cURL’ing the Twitter Public Timeline
This should bring back the RSS feed for the Twitter Public Timeline, as seen in the following screenshot:
Great – but we’re not very interested in the public timeline are we? Let’s tell Twitter who we are and ask for the timeline of only the people we are following. This time, we will ask for a response in the JSON (JavaScript Object Notation) format. Please be sure to substitute your own Twitter username and password for the values below. And no, my Twitter password is not “password”!
curl -u joelennon:password http://twitter.com/statuses/friend_timeline.json
Listing 3 – cURL’ing our Friends’ Timeline
In this example, we are using HTTP authentication to tell Twitter who we are, and asking it to return a JSON representation of our friends’ timeline. For a sample of the output, see Figure 3 below:
At this point, you may be wondering what use all of the mumbo-jumbo we are receiving as a response is to us. In fact, in this tutorial, it’s not much use to us at all as we are only interested in updating Twitter. If we wanted to display our own, our friends or public tweets however, we would be able to parse this information and display it in a readable format. The Twitter API provides an array of methods for pulling back information like this, including:
- public_timeline
- friends_timeline
- user_timeline
- show
- replies
- friends
- followers
- many more…
If you would like to delve deeper into these methods, and the Twitter API in general, check out the REST API Documentation on the Twitter API Wiki. It has a host of information and examples on how to use the Twitter API. Now let’s get back to the tutorial!
Up until this point, we have concentrated mainly on retrieving data from Twitter. But we want to send updates to Twitter! Luckily, cURL allows us to neatly send POST data along with our HTTP request. To post an update, issue the following command in your command prompt:
curl -u joelennon:password -d status="Testing out using cURL for Twitter updates" http://twitter.com/statuses/update.xml
Listing 4 – Update Twitter with CURL
As previously, you will receive a response in the format you specified in the request (in this case, XML). This should look similar to the screenshot below:
But, more importantly, if you check out your Twitter page, you will see that your timeline has been updated with a new post – you guessed it, the one we just sent. To change the content of the post, simply change the text between the quote symbols in Listing 4 above. I think you’ll agree, using the Twitter API with curl is pretty easy! Now let’s take things a step further and create a script that will post the update for us, so that we don’t have to issue the long curl command every time we want to post.
Open a text editor (Notepad will do fine) and add the command from Listing 4 above to it. Feel free to change the status text to something else! Now go to File -> Save As and save it as “twitter.bat” in the C:\curl directory. Be sure to include the quotes when you are saving the file, otherwise Notepad will probably try to save it as .txt file, and you’ll end up with a file named twitter.bat.txt instead!
Now go back to your command prompt and ensure that you have changed in to the C:\curl directory. Enter the following command:
twitter.bat
Listing 5 – Running our Twitter script
Hey presto, your Twitter update has been posted! While this is nice and short, it’s still a bit of a pain as we have to modify the twitter.bat file everytime to change the status text. Let’s fix that. Re-open twitter.bat in Notepad, and change the contents to the following:
@ECHO OFF SET STATUS=%* c:\curl\curl.exe -u joelennon:password -d status="%STATUS%" http://twitter.com/statuses/update.xml
Listing 6 – Update twitter.bat file
We have changed the batch file so that it does not display the command each time it runs, and it sets a variable, STATUS to all the arguments entered when the command is executed. We then use this STATUS variable in our curl command instead of static text. This allows us to enter the status text we wish to update Twitter with when we run our script. This time, try running the command in Listing 7 below:
twitter.bat Passing arguments to the batch file
Listing 7 – Running our updated script
Well would you look at that, it’s submitted the Twitter update using the text we specified after the twitter.bat command! Take a step back and look at what you’ve just created – a Twitter updater client! Sure it’s basic, but it works! Now that we have the script to post our Twitter updates created, let’s look at how we can schedule it to automatically post an update at a specified date and time.
A feature of the Windows operating system that is often overlooked is the Task Scheduler. This allows you to create scheduled tasks that will run on a certain date and time. This tool has a GUI interface and a command-line interface for scheduling tasks, but it can be quite complex. Instead, we are going to use the at command, which is included with any NT-based Windows platform (NT/2000/XP/Vista/Server). This is a very basic and simple to use command-line scheduler.
I am writing this particular paragraph at 2:26pm. The line below will automatically send a tweet at 2:27pm. Change the time to the 24-hour value for a time that’s a few minutes into the future for you (otherwise it will send the next time 2:27pm comes around, and you might have to wait a long time to test it worked!)
at 14:27 cmd /c c:\curl\twitter.bat This is a scheduled tweet!
Listing 8 – Scheduling a tweet
The at command is quite simple, but it has some nice features that allow you to schedule tasks to run at set intervals – for example every Monday at 9.00am. For further information, see this Microsoft Knowledgebase article on the at command. Note in the above example that we preceded our twitter script file with the command “cmd /c”. This might not mean anything to you, but it is required in order for the script to work, as we are running a batch file and not a regular executable. This basically tells the scheduler to start a command window, run the specified command and close the command window when done.
Congratulations, you now have a way of automating your tweets so that they are posted at a set date/time or even at a regular interval. It’s not the prettiest solution in the world, but it’s simple and you have probably learned a bit about the Twitter API (and batch files and the scheduling tasks!) in the process. If you have any questions or need some help with this, feel free to leave a comment and I’ll do my best to help you out!
The Irish Blogosphere
Ireland has a strong community of bloggers, who are not afraid to voice their opinions and post honest commentary about a wide spectrum of topics – including but not limited to – politics, current affairs, consumer issues, technology, software development, business and enterprise. This community is a very social one, and those involved are not afraid to interact with one another – whether it be by means of commenting on one another’s blog posts, communicating via Twitter or arranging conferences and meet-ups – the key principle is getting involved.
My experience of the Irish blogosphere over the past number of years has been as more of an outsider looking in. Unfortunately I don’t have as much time as I’d like to post to my blog, interact on Twitter, or attend events and conferences. I do, however, read my favourite blogs on a daily basis using Google Reader, and have a read through the latest Twitter posts by those I follow every few hours.
If you are new to the Irish blogging community, you may be wondering how to start finding blogs that are of interest to you. A good place to start is Twitter – almost all of Ireland’s most influential bloggers are using the microblogging service, and most will post links to their blog updates as soon as they post them. I have included Twitter usernames, where available, for each of the bloggers I mention below. The following list is by no means exhaustive – but keeping track of these blogs is a good start to getting to know the Irish blogosphere. You will find many other interesting Irish blogs by reading these blogs and the comments visitors leave on each post. Many of these bloggers post frequent lists of links to interesting blog posts from the around the Irish blogosphere – for example, Damien Mulley’s “Fluffy Links”, Alexia Golez’s “Red Links” and Joe Scanlon’s “Little Links”. These are a great way to find your way around, so I highly recommend checking them out.
Robin Blandford
Web: http://www.bytesurgery.com/blog/
RSS: http://www.bytesurgery.com/blog/feed/
Topics: Technology, Design, Blogging, Business, Media
Twitter: @robinb
Suzy Byrne
Web: http://www.mamanpoulet.com/
RSS: http://www.mamanpoulet.com/feed/
Topics: Current Affairs, Politics, Equality, Blogging
Twitter: @suzybie
Tommy Collison
Web: http://trusttommy.com/
RSS: http://trusttommy.com/feed/
Topics: Technology, Blogging, Science, iPhone
Twitter: @TrustTommy
Sabrina Dent
Web: http://www.sabrinadent.com/
RSS: http://feeds.feedburner.com/SabrinaDent
Topics: Design, Internet Marketing, Advertising, Politics, Technology
Twitter: @SabrinaDent
Alexia Golez
Web: http://golez.net/
RSS: http://feeds.feedburner.com/alexiablogs/TBag
Topics: Politics, Photography, Business, Culture, Blogging
Twitter: @lexia
“Grandad” (Head Rambles)
Web: http://www.headrambles.com/
RSS: http://feeds.feedburner.com/HeadRambles
Topics: Blogging, Current Affairs, Politics, Technology
Twitter: @headrambles
Niall Harbison
Web: http://www.niallh.com/
RSS: http://feeds.feedburner.com/NiallHarbisoncom
Topics: Business, Enterprise, Food, Blogging, Twitter, Video
Twitter: @NiallHarbison
Twenty Major
Web: http://twentymajor.net/
RSS: http://feeds.feedburner.com/twentymajor
Topics: Politics, Satire, Current Affairs, Comedy
Twitter: @twentymajor
Damien Mulley
Web: http://mulley.net
RSS: http://feeds.feedburner.com/DamienMulley
Topics: Politics, Blogging, Communications, Broadband, Internet Marketing
Twitter: @damienmulley
Pat Phelan
Web: http://patphelan.net
RSS: http://feeds.feedburner.com/RoamFree
Topics: Telecommunications, Mobile Phones, Roaming, Technology, Innovation
Twitter: @patphelan
Joe Scanlon
Web: http://joescanlon.net/
RSS: http://joescanlon.net/feed/
Topics: Business, Technology, Blogging, Twitter, UCC, Events
Twitter: @joescanlon
Gavin Sheridan
Web: http://www.gavinsblog.com/
RSS: http://www.gavinsblog.com/feed/
Topics: Politics, Current Affairs, Technology
Twitter: @gavinsblog
Why not contribute to the Irish blogging community by starting your own blog? There are various sites out there offering free or inexpensive hosted blog solutions that you can set up in minutes, without having to get your hands dirty with any technical work. These include:
Alternatively, you can bring your own hosting and domain name and install one of the following software packages which will allow you to configure and tinker your blog to your exact requirements:
All of the above blog services and software packages are relatively easy to use, self explanatory and include excellent documentation that will help you get your blog up and running in no time. If you want any advice on starting a blog or technical guidance on setting up any of the above, feel free to drop me a line on joe at this domain.















