quick & dirty quote fetcher in bash
February 04, 2002
Here is another quick hack -- a version of quoter written in bash. This goes to show that a "language" (more of a programming environment, really) like bash can compete against a well-designed and rich language like PHP. Granted, a true demonstration of this power would have some of the stuff that is present in quoter: data abstractions, error handling, configurability...
But like I said, this was a quick hack. Very much a hack: error checking is non-existent. You'll want to go over the source to make sure your environment is set up properly:
- Create a ~/.quotecache.
- Modify the aging value in the script if you want more frequent price updates.
- Change the pathname: you can probably replace /home/administrator with ~. The handicapped version of bash I'm using wasn't expanding ~ properly so I hardcoded the path.
- You'll need wget (most people will already have this installed).
I'm fairly sure there is a better way of doing the age test, but what is in there works so it will have to do for now. Also, I'm missing the xml parser for python in this environment, or I would have used xmlgrep to parse the quote from the file. As a demonstration of how you might use this as the basis for other little hacks, here's how I use it:
#!/bin/sh
tickerlist="ge msft mrk"
for ticker in $tickerlist
do
last=`quote $ticker last`
change=`quote $ticker change`
vol=`quote $ticker vol`
echo "$ticker $last $change $vol"
done
Since this stuff is all so simple and almost trivial to put together, it is in the public domain. Do with it what you will. Of course, if you add error checking or improve anything else and you want to share, I'd love to hear about it. (brian@bstpierre.org)