Recently I discover this awesome website http://www.publicapis.com/, and have been trying to think of cool stuff I can use it for ever since!

The first thing that caught my eye was this one: http://www.publicapis.com/community/wikipedia

Wikipedia! I figured most APIs are easy enough to play with using cURL so how about I make a shell program that can summon Wikipedia information fast and easy?

Here's a sample:

$ wiki hercules Hercules Hercules is the Roman name for the Greek divine hero Heracles, who was the son of Zeus (Roman equivalent Jupiter) and the mortal Alcmene. In classical mythology, Hercules is famous for his strength and for his numerous far-ranging adventures. The Romans adapted the Greek heros iconography and myths for their literature and art under the name Hercules. In later Western art and literature and in popular culture, Hercules is more commonly used than Heracles as the name of the hero. Hercules was a multifaceted figure with contradictory characteristics, which enabled later artists and writers to pick and choose how to represent him. This article provides an introduction to representations of Hercules in the later tradition.

Cool, right? Here's the Gist where I uploaded the program: https://gist.github.com/thedouglenz/193defdb711e0e54d68a

It requires PHP to run. On Ubuntu, you can get it via apt-get install php5 php5-curl

If you want to have it and use it just download the file in that Gist, place it in your /home/[username]/bin directory. Rename it to wiki and run chmod +x wiki . Logout, log back in, or open another shell, and you're good to go!

Recommended install:

$ wget -O /home/[username]/bin/wiki https://cdn.rawgit.com/thedouglenz/193defdb711e0e54d68a/raw/ $ chmod +x /home/[username]/bin/wiki

Mac OS X users:

$ # if you don't have a personal bin directory ... $ mkdir /Users/[username]/bin $ # and then ... $ wget -O /Users/[username]/bin/wiki https://cdn.rawgit.com/thedouglenz/193defdb711e0e54d68a/raw/ $ # and if you haven't added you personal bin directory to your PATH $ export PATH = /Users/[username]/bin: $PATH $ source ~/.profile

I'm currently iffy about the Mac instructions because I don't own one so be easy on me. :-P

NOTE

Please note that allowing strings from the MediaWiki API to be passed directly as an argument to a shell command could be harmful if someone maliciously edited the article being queried to include special shell characters and commands.