Update: A better version of the weather script is discussed above
Lately, I've revisited ruby for various small code projects. It's virtues are extolled at length here, so I won't bother other than to say I like it. The following programs are some practical examples of ruby (though not the most elegant ways of doing so), and are just plain useful (at least to me).
Weather
I wanted to fetch weather forecasts for my area (or any other I happened to be visiting). There are several weather reporters available, and I've tried many of them. However, they were all in widget form, and tied to some desktop environment, dock, or some such. I decided to create one I could call from the command line (handy, since I soon moved to awesomewm, which has no desktop or dock to speak of. More on that another time.)
My weather reporter downloads two different pages off of weather.com (the "now" page and the "forecast" page), scans them for the relevant temperatures, and displays them neatly on the screen (with ASCII colors :). It defaults to San Luis Obispo (my current home base), but will take a zip code as an argument.
The code: weather-old.rb
Battery
For similar reasons to the weather, I wanted a script to give me a simple battery readout, perfect for status bars or command lines. After a bit of research, I found that (in Linux) the battery information is stored in various files in /proc/acpi/battery/BAT#. It was just a matter of scanning these files, doing a bit of division, and formatting the output.
Here is the code: battery.rb
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment