myforecast: a companion to myradar
by Andrew Newman
One of a series of example shells:
This contribution is a simple bash shell to call up the weather forecast
from Wunderground.com.
What is nice about this shell and the wunderground site, is that you can call up the forecast for just about
anywhere (at least from what I can tell).
myforecast:
#!/bin/bash
# program myforecast
# version 1.0
# written by Andrew V. Newman
# last modified Tue Feb 24 17:21:57 MST 2004
# shell script to bring up a weather forecast either on a
# graphical browser or in the console if the screen is not available.
# Create a default location. This assumes you live in the US as I do.
CITY=Los_Alamos # use underscore to separate multi-word cities
STATE=NM
# Sets a default URL BASE
URL_SUF=US/$STATE/$CITY.html
# Set the default graphical browser
# I like galeon, but it may not be installed on your machine.
GUI_BROWSER=/usr/bin/galeon
GUI_BROWSER=/usr/bin/konqueror
GUI_BROWSER=/usr/bin/mozilla
# ---------------------------- #
# Shouldn't have to change these
LYNX=/usr/bin/lynx
URL_BASE=http://www.wunderground.com/
MBL_URL_BASE=http://mobile.wunderground.com/
# If you use just one variable
if [ $1 ] ; then
URL_SUF=cgi-bin/findweather/getForecast?query=$1
fi
# If you use two variables
if [ $2 ]; then
CITY=$1
STATE=$2
URL_SUF=US/$STATE/$CITY.html
fi
# If you can display a window on your terminal it will
# bring up your forecast in a graphical browser
if [ $DISPLAY ]; then
URL=${URL_BASE}${URL_SUF}
$GUI_BROWSER $URL 2> /dev/null
# Otherwise, it will bring it up on screen using a version
# of the website set up for mobile computers (no ads and few graphics,
# which will not be displayed anyway).
else
URL=${MBL_URL_BASE}${URL_SUF}
$LYNX $URL -dump 2> /dev/null >forecast.temp
# displays forecast as text
more forecast.temp
# remove temporary file
rm forecast.temp
fi
# exit cleanly
exit 0
A copy of this script exists in /home/anewman/bin/myforecast on terremoto
Once you have a copy on your system, all you need to do is:
- Modify the first two variables to create your own defaults.
- Change permissions of the file so that you can execute it:
% chmod 755 myforecast
- Move file to a directory in your path:
I would suggest creating a bin directory from your home for all
shells and then making certain it is included in your path.
% mkdir ~/bin % mv myforecast ~/bin/
If it is not already there, add the following line to ~/.cshrc if you are using a csh or tcsh shell
path = ( $path ~/bin)
Or, if you are using bash add the following line to ~/.bashrc
PATH=$PATH:~/bin
If you look through the program, you will notice that there is a default set up for my old home town. Certainly you
should change to whatever you want. It is important to note here, that though wunderground.com gives forecasts for
cities around the globe, the script is really set to work within the US.
Now that you have set your defaults, give the program a shot. Try running the following commands:
% myforecast
% myforecast Chicago IL
% myforecast Tokyo
% myforecast 30332
Course Home | anewman gatech.edu | Updated:
Mon Sep 18 18:16:49 EDT 2006
|