From ferguson@cs.rochester.edu Tue Jun 30 13:51:19 1992
To: Perl-Users@fuggles.acc.Virginia.EDU
From: ferguson@cs.rochester.edu (George Ferguson)
Crossposted-To: alt.sources
Subject: Updated weather script
Date: 30 Jun 92 16:10:07 GMT
Reply-To: ferguson@cs.rochester.edu (George Ferguson)
SUB: Updated weather script
SUM: ferguson@cs.rochester.edu (George Ferguson), ferguson@cs.rochester.edu (George Ferguson)->Perl-Users@fuggles.acc.Virginia.EDU

Archive-Name: weather
Submitted-by: George Ferguson <ferguson@cs.rochester.edu>

I've packaged up the script I posted last week into a more complete
distribution. You'll find a README, and a Makefile that makes
customization and installation easier. Please read the README before
doing anything (you can even read it here at the top of the shar).
Please also note that I do *not* want to hear about this script
needing changes every time the weather server menus change, as I make
clear in the README and manpage. I'd be happy to hear about bugs in
the logic of the script, or the docs, or things like that.

George

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README Makefile weatherT.pl weather.pl weatherT.man
#   weather.man
# Wrapped by ferguson@swan.cs.rochester.edu on Tue Jun 30 12:08:50 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(3266 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X		      README for weather script
X
X	George Ferguson, ferguson@cs.rochester.edu, 30 Jun 1992
X
XOVERVIEW:
X  This package is primarily a Perl script that connects to the Weather
X  Underground at the University of Michigan and retrieves forecasts for
X  a specified city, state, or Canadian region. The distribution includes
X  the following files:
X
X	 README		this file
X	 Makefile	helpful for installing, and for completeness
X	 weather.pl	the real Perl script with local substitutions made
X	 weatherT.pl	the template Perl script
X	 weather.man	the manpage
X
X  See the man page for the codes used to specify cities or regions.
X
XWEATHER UNDERGROUND:
X  The Weather Underground provides more detailed information using an
X  interactive interface than can be extracted automatically by this
X  script. Do "telnet downwind.sprl.umich.edu 3000" to connect
X  interactively. Please limit your connection time to help lower server
X  load.
X
XSUPPORT:
X  While I welcome reports of bugs in the program, I have neither the
X  time nor the desire to constantly maintain this program. The script
X  can get confused when the weather server's menu change, and I'd prefer
X  to not be flooded with messages about the script being broken every
X  time this happens. If something like that happens, and if I fix the
X  script to handle it, you can be sure I will post the changes. However,
X  please do not mail me requesting new versions. The Perl script is
X  simple enough for you to have a go at fixing it yourself and posting
X  the changes. Both the Net and I will love you for it.
X
X  From sdm@madlab.sprl.umich.edu (Home of the Weather aka Jeff Masters):
X  >A new mailing list has been created for all those Weather Underground
X  >users who utilize shell scripts to automatically grab forecasts. I
X  >will post mail to this list whenever a change is made to the Weather
X  >Underground which may impact your shell script. To add your name to the
X  >list, send a note to "weather-users-request@zorch.sf-bay.org".
X
XCOPYRIGHT:
X  This code is based on an earlier version of the weather script which
X  was: Copyright 1991 Frank Adelstein (frank@cis.ohio-state.edu). See
X  the file weather.pl for policy details. Any parts of the package
X  attributable only to me (GF) are in the public domain.
X
XINSTALLATION:
X  Edit the Makefile to set DEFCITY to the code of the city whose forecast
X  you want retrieved when no code is given on the command line, and to
X  set PERLLOC to the absolute pathname of your Perl interpreter. Then
X  do "make" to create the script "weather.pl" from the template script
X  "weatherT.pl". Alternatively, or if you don't have sed(1), copy
X  "weatherT.pl" to "weather.pl" and edit the obvious places to set
X  these parameters. Similarly for "weatherT.man" and "weather.man".
X
X  Edit the Makefile to set BINDIR and MANDIR appropriately if you will
X  be installing, then do "make install install.man" to put the script
X  and manpage in place.
X
XHISTORY:
X  28 Jun 1991: Original release by FNA.
X  24 Feb 1992: Released GF version with Canadian region stuff.
X  26 Jun 1992: Fixed for new server menus. Big cleanup.
X  29 Jun 1992: Fixed severe weather statment stuff, with help from
X	       kenr@storage.tandem.com.
X  30 Jun 1992: Use <<...>> stuff in weatherT.pl and generate weather.pl.
END_OF_FILE
if test 3266 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(1336 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#
X# Makefile for weather: Retrieve forecasts from Weather Underground
X#
X# George Ferguson, ferguson@cs.rochester.edu, 30 Jun 1992.
X#
X
X# Default city code (for when "weather" is run with no argument)
XDEFCITY = ROC
X
X# Where is your Perl interpreter, for the #! incantation
XPERLLOC = /usr/local/bin/perl
X
X# Installation destinations
XBINDIR = /usr/local/bin
XMANDIR = /usr/local/man/man1
XMANEXT = 1
X
X##############################
X# Nothing to change below here
X
XSERVERHOST = downwind.sprl.umich.edu
XSERVERPORT = 3000
X
XFILES = README Makefile weatherT.pl weather.pl weatherT.man weather.man
X
X# If you don't have sed, you'll have to copy and edit the template files
X# by hand.
Xweather.pl: weatherT.pl Makefile
X	sed -e '1d' \
X	    -e 's@<<PERLLOC>>@$(PERLLOC)@' \
X	    -e 's@<<DEFCITY>>@$(DEFCITY)@' \
X	    -e 's@<<SERVERHOST>>@$(SERVERHOST)@' \
X	    -e 's@<<SERVERPORT>>@$(SERVERPORT)@' <weatherT.pl >weather.pl
X
Xweather.man: weatherT.man Makefile
X	sed -e '1d' \
X	    -e 's@<<DEFCITY>>@$(DEFCITY)@' \
X	    -e 's@<<SERVERHOST>>@$(SERVERHOST)@' \
X	    -e 's@<<SERVERPORT>>@$(SERVERPORT)@' <weatherT.man >weather.man
X
Xinstall: weather.pl
X	cp weather.pl $(BINDIR)/weather
X	chmod a+x $(BINDIR)/weather
X
Xinstall.man: weather.man
X	cp weather.man $(MANDIR)/weather.$(MANEXT)
X	chmod a+r $(MANDIR)/weather.$(MANEXT)
X
Xshar:
X	shar $(FILES) >weather.shar
END_OF_FILE
if test 1336 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'weatherT.pl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'weatherT.pl'\"
else
echo shar: Extracting \"'weatherT.pl'\" \(7257 characters\)
sed "s/^X//" >'weatherT.pl' <<'END_OF_FILE'
X** This file is "weatherT.pl", which is used to generate "weather.pl" **
X#!<<PERLLOC>>
X#
X# A perl script to connect to the 'weather server' at
X# Michigan and get the forcast for whatever city
X# you want (3 letter code -- columbus 'cmh' by default).
X#
X# Alternatively, you can get the current information for
X# a state if you enter a 2 letter code.
X#
X# Thanks to J Greely for the original network code, and
X# Tom Fine for assistance and harassment.
X#
X# Copyright 1991 Frank Adelstein.  All Rights Reserved.
X#
X# Permission to use, copy, modify, and distribute this
X# software is hereby granted without fee, provided that
X# the copyright notice and permission notice are not removed.
X#
X# --FNA 6/28/91
X#
X# Hacked by George Ferguson (ferguson@cs.rochester.edu) to include
X# Canadian forecasts by zone number.
X#
X# From the README (which you should have read already):
X#  While I (gf) welcome reports of bugs in the program, I have neither the
X#  time nor the desire to constantly maintain this program. The script
X#  can get confused when the weather server's menu change, and I'd prefer
X#  to not be flooded with messages about the script being broken every
X#  time this happens. If something like that happens, and if I fix the
X#  script to handle it, you can be sure I will post the changes. However,
X#  please do not mail me requesting new versions. The Perl script is
X#  simple enough for you to have a go at fixing it yourself and posting
X#  the changes. Both the Net and I will love you for it.
X#
X# ferguson@cs.rochester.edu, 26 Jun 1992: Mods for new weather service menus.
X#   I ripped lots of stuff out of this version, some of it may have to be
X#   put back, but it works fine for me.
X#   It's much easier to navigate the system now (for US forecasts, anyway),
X#   so the interaction loop is considerably simplified. The Canadian stuff
X#   is relatively straightforward also.
X# kenr@storage.tandem.com 29 Jun 1992: Handle severe weather statements.
X# gf 29 Jun 1992: More severe weather stuff for Canadian forecasts.
X# gf 30 Jun 1992: Use <<...>> stuff in weatherT.pl then generate weather.pl.
X#
X
X$SERVER = "<<SERVERHOST>>";
X$PORT   = "<<SERVERPORT>>";
X
X#
X# Parse argument, if any
X#
X$CITY = $ARGV[0]; 
Xif ($CITY eq "") {
X    $CITY = "<<DEFCITY>>";	# No arg -> use default city
X}
X
X#
X# Allow 4-char symbolic names for Canadian reports.
X#
X%canNames = ("salt","1",  "SALT","1",
X	     "calt","2",  "CALT","2",
X	     "nalt","3",  "NALT","3", "nebc","3", "NEBC","3",
X	     "cobc","4",  "COBC","4",
X	     "inbc","5",  "INBC","5",
X	     "sman","6",  "SMAN","6",
X	     "nman","7",  "NMAN","7",
X	     "nova","8",  "NOVA","8",
X	     "pedi","9",  "PEDI","9",
X	     "newb","10", "NEWB","10",
X	     "labr","11", "LABR","11",
X	     "nfld","12", "NFLD","12",
X	     "sont","13", "SONT","13",
X	     "nont","14", "NONT","14",
X	     "nwon","15", "NWON","15",
X	     "ssas","16", "SSAS","16",
X	     "nsas","17", "NSAS","17",
X	     "yukn","18", "YUKN","18",
X	     "sque","19", "SQUE","19", "ottw","19", "OTTW","19",
X	     "nque","20", "NQUE","20");              
X#
X# If we're given one of these names, use the number instead.
X#
Xif ($t=$canNames{$CITY}) {
X    $CITY = $t;
X}
X
X#
X# Check argument
X#
Xif ($CITY =~ /[0-9]+/) {
X    $ISCAN = 1;
X} elsif (length ($CITY) == 3 ) {
X    $ISCAN = 0;
X} elsif (length ($CITY) == 2 ) {
X    $ISCAN = 0;
X} else {
X    print "Must be either a 2 letter state code or 3 letter city code.\n";
X    print "Can also be a numeric Canadian zone number or symbolic name.\n";
X    exit (1);
X}
X
X#
X# Connect to the server
X#
Xlocal($sockaddr,$here,$there,$response,$tries) = ("Snc4x8");
X$here  = pack($sockaddr,2,0,&getaddress("localhost"));
X$there = pack($sockaddr,2,$PORT,&getaddress($SERVER));
Xprint "\nConnecting to $SERVER.";
Xdie "socket: $!\n" if (!socket(SOCK,2,1,6));
Xprint ".";
Xdie "connect: $!\n" if (!connect(SOCK,$there));
Xprint ".connected\n";
Xselect(SOCK); $| = 1;
Xselect(STDOUT); $| = 1;       # make unbuffered
X
X#
X# Initialize
X#
X$SHOWIT = 0;			# Should we print?
X$MAINMENU = 0;			# Seen main menu once already?
X$CANMENU = 0;			# See Canadian menu once already?
X
X#
X# Interact...
X#
Xwhile (read(SOCK,$c,1)) {	# Get a character
X    if ($c eq "\n") {		# Newline -> maybe print, start new line
X	if ($SHOWIT == 1) {
X	    print $curline, "\n";
X	}
X	$curline = "";
X	next; 
X    }
X    if ($c eq "\r") { next; }	# Return -> ignore
X    $curline .= $c;		# Else add char to current line
X	
X    #
X    # Now test the current line so far to see what action to take, if any.
X    #
X    if ($curline =~ /Press Return for menu, or enter 3 letter forecast city code:/) { # At first prompt...
X	if ($ISCAN) {
X	    printf SOCK "\n";	# For Canadian forecast, go via main menu
X	} else {
X	    printf SOCK "%s\n", $CITY; # For US, bypass menu
X	    $curline = "";
X	    &showiton("us city/state");
X	}
X    } elsif ($curline =~ / Selection:/) { # In main menu...
X	if ($ISCAN) {		# Canadian forecast...
X	    if (!$MAINMENU) {	    # At main menu, select Canadian forecasts
X		$MAINMENU = 1;
X		printf SOCK "2\n";  # Canadian forecast is item 2!!
X		$curline = "";
X	    } elsif (!$CANMENU) {   # At Canadian menu, select region
X		$CANMENU = 1;
X		printf SOCK "%s\n", $CITY;
X		&showiton("canadian region");
X		$curline = "";
X	    } else {
X		printf SOCK "X\n";  # Otherwise exit
X	    }
X	} else {
X	    printf SOCK "X\n";	# Otherwise exit
X	}
X    } elsif ($curline =~ / Invalid 3-letter city code./) {
X	printf SOCK "X\n";
X	printf "%s is an invalid 3 letter city code.\n", $CITY;
X	&showitoff("3-letter");
X    } elsif ($curline =~ / Invalid city or state code./) {
X	printf SOCK "X\n";
X	printf "%s is an invalid city or state code.\n", $CITY;
X	&showitoff("invalid");
X    } elsif ($curline =~ / CITY FORECAST MENU/) {
X	&showitoff("city forecast");
X    } elsif ($curline =~ / CURRENT WEATHER MENU/) {
X	&showitoff("city forecast");
X    } elsif ($curline =~ / CANADIAN FORECASTS/) {
X	&showitoff("canadian forecasts");
X    } elsif ($curline =~ / Press Return to continue: /) {
X	printf SOCK "\n";
X	$curline = "";
X	&showiton("Return to continue");
X    } elsif ($curline =~ / Press Return to continue printing or M to return to menu: /) {
X	printf SOCK "\n";
X	$curline = "";
X	&showiton("Return to continue printing");
X    } elsif ($curline =~ / Press Return to display statement, M for menu: /) {
X	# kenr@storage.tandem.com: Handle severe weather statement in city
X        printf SOCK "\n";
X        $curline = "";
X        &showiton("Return to display statment (city)");
X    } elsif ($curline =~ / Press [rR]eturn to display statement, M to display main menu: /) {
X	# gf: Similarly for severe Michigan weather and Canadian forecasts
X	if ($ISCAN) {
X	    printf SOCK "M\n";
X	    &showitoff("Return to display statement (main)");
X	} else {
X	    printf SOCK "\n";
X	    &showiton("Return to display statement (main)");
X	}
X        $curline = "";
X    }
X}
X
X#
X# Clean up and done
X#
Xclose(SOCK);
Xexit(0);
X
X#####################################################
X
Xsub getaddress {
X    local($host) = @_;
X    local(@ary);
X    @ary = gethostbyname($host);
X    return(unpack("C4",$ary[4]));
X}
X
Xsub showitoff {
X    local($txt) = @_;
X    &maybeprint ("showit off ($txt)\n");
X    $SHOWIT = 0;
X}
X
Xsub showiton {
X    local($txt) = @_;
X    &maybeprint ("showit on ($txt)\n");
X    $SHOWIT = 1;
X}
X
Xsub maybeprint {
X#    print @_;
X}
END_OF_FILE
if test 7257 -ne `wc -c <'weatherT.pl'`; then
    echo shar: \"'weatherT.pl'\" unpacked with wrong size!
fi
chmod +x 'weatherT.pl'
# end of 'weatherT.pl'
fi
if test -f 'weather.pl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'weather.pl'\"
else
echo shar: Extracting \"'weather.pl'\" \(7183 characters\)
sed "s/^X//" >'weather.pl' <<'END_OF_FILE'
X#!/usr/local/bin/perl
X#
X# A perl script to connect to the 'weather server' at
X# Michigan and get the forcast for whatever city
X# you want (3 letter code -- columbus 'cmh' by default).
X#
X# Alternatively, you can get the current information for
X# a state if you enter a 2 letter code.
X#
X# Thanks to J Greely for the original network code, and
X# Tom Fine for assistance and harassment.
X#
X# Copyright 1991 Frank Adelstein.  All Rights Reserved.
X#
X# Permission to use, copy, modify, and distribute this
X# software is hereby granted without fee, provided that
X# the copyright notice and permission notice are not removed.
X#
X# --FNA 6/28/91
X#
X# Hacked by George Ferguson (ferguson@cs.rochester.edu) to include
X# Canadian forecasts by zone number.
X#
X# From the README (which you should have read already):
X#  While I (gf) welcome reports of bugs in the program, I have neither the
X#  time nor the desire to constantly maintain this program. The script
X#  can get confused when the weather server's menu change, and I'd prefer
X#  to not be flooded with messages about the script being broken every
X#  time this happens. If something like that happens, and if I fix the
X#  script to handle it, you can be sure I will post the changes. However,
X#  please do not mail me requesting new versions. The Perl script is
X#  simple enough for you to have a go at fixing it yourself and posting
X#  the changes. Both the Net and I will love you for it.
X#
X# ferguson@cs.rochester.edu, 26 Jun 1992: Mods for new weather service menus.
X#   I ripped lots of stuff out of this version, some of it may have to be
X#   put back, but it works fine for me.
X#   It's much easier to navigate the system now (for US forecasts, anyway),
X#   so the interaction loop is considerably simplified. The Canadian stuff
X#   is relatively straightforward also.
X# kenr@storage.tandem.com 29 Jun 1992: Handle severe weather statements.
X# gf 29 Jun 1992: More severe weather stuff for Canadian forecasts.
X# gf 30 Jun 1992: Use <<...>> stuff in weatherT.pl then generate weather.pl.
X#
X
X$SERVER = "downwind.sprl.umich.edu";
X$PORT   = "3000";
X
X#
X# Parse argument, if any
X#
X$CITY = $ARGV[0]; 
Xif ($CITY eq "") {
X    $CITY = "ROC";	# No arg -> use default city
X}
X
X#
X# Allow 4-char symbolic names for Canadian reports.
X#
X%canNames = ("salt","1",  "SALT","1",
X	     "calt","2",  "CALT","2",
X	     "nalt","3",  "NALT","3", "nebc","3", "NEBC","3",
X	     "cobc","4",  "COBC","4",
X	     "inbc","5",  "INBC","5",
X	     "sman","6",  "SMAN","6",
X	     "nman","7",  "NMAN","7",
X	     "nova","8",  "NOVA","8",
X	     "pedi","9",  "PEDI","9",
X	     "newb","10", "NEWB","10",
X	     "labr","11", "LABR","11",
X	     "nfld","12", "NFLD","12",
X	     "sont","13", "SONT","13",
X	     "nont","14", "NONT","14",
X	     "nwon","15", "NWON","15",
X	     "ssas","16", "SSAS","16",
X	     "nsas","17", "NSAS","17",
X	     "yukn","18", "YUKN","18",
X	     "sque","19", "SQUE","19", "ottw","19", "OTTW","19",
X	     "nque","20", "NQUE","20");              
X#
X# If we're given one of these names, use the number instead.
X#
Xif ($t=$canNames{$CITY}) {
X    $CITY = $t;
X}
X
X#
X# Check argument
X#
Xif ($CITY =~ /[0-9]+/) {
X    $ISCAN = 1;
X} elsif (length ($CITY) == 3 ) {
X    $ISCAN = 0;
X} elsif (length ($CITY) == 2 ) {
X    $ISCAN = 0;
X} else {
X    print "Must be either a 2 letter state code or 3 letter city code.\n";
X    print "Can also be a numeric Canadian zone number or symbolic name.\n";
X    exit (1);
X}
X
X#
X# Connect to the server
X#
Xlocal($sockaddr,$here,$there,$response,$tries) = ("Snc4x8");
X$here  = pack($sockaddr,2,0,&getaddress("localhost"));
X$there = pack($sockaddr,2,$PORT,&getaddress($SERVER));
Xprint "\nConnecting to $SERVER.";
Xdie "socket: $!\n" if (!socket(SOCK,2,1,6));
Xprint ".";
Xdie "connect: $!\n" if (!connect(SOCK,$there));
Xprint ".connected\n";
Xselect(SOCK); $| = 1;
Xselect(STDOUT); $| = 1;       # make unbuffered
X
X#
X# Initialize
X#
X$SHOWIT = 0;			# Should we print?
X$MAINMENU = 0;			# Seen main menu once already?
X$CANMENU = 0;			# See Canadian menu once already?
X
X#
X# Interact...
X#
Xwhile (read(SOCK,$c,1)) {	# Get a character
X    if ($c eq "\n") {		# Newline -> maybe print, start new line
X	if ($SHOWIT == 1) {
X	    print $curline, "\n";
X	}
X	$curline = "";
X	next; 
X    }
X    if ($c eq "\r") { next; }	# Return -> ignore
X    $curline .= $c;		# Else add char to current line
X	
X    #
X    # Now test the current line so far to see what action to take, if any.
X    #
X    if ($curline =~ /Press Return for menu, or enter 3 letter forecast city code:/) { # At first prompt...
X	if ($ISCAN) {
X	    printf SOCK "\n";	# For Canadian forecast, go via main menu
X	} else {
X	    printf SOCK "%s\n", $CITY; # For US, bypass menu
X	    $curline = "";
X	    &showiton("us city/state");
X	}
X    } elsif ($curline =~ / Selection:/) { # In main menu...
X	if ($ISCAN) {		# Canadian forecast...
X	    if (!$MAINMENU) {	    # At main menu, select Canadian forecasts
X		$MAINMENU = 1;
X		printf SOCK "2\n";  # Canadian forecast is item 2!!
X		$curline = "";
X	    } elsif (!$CANMENU) {   # At Canadian menu, select region
X		$CANMENU = 1;
X		printf SOCK "%s\n", $CITY;
X		&showiton("canadian region");
X		$curline = "";
X	    } else {
X		printf SOCK "X\n";  # Otherwise exit
X	    }
X	} else {
X	    printf SOCK "X\n";	# Otherwise exit
X	}
X    } elsif ($curline =~ / Invalid 3-letter city code./) {
X	printf SOCK "X\n";
X	printf "%s is an invalid 3 letter city code.\n", $CITY;
X	&showitoff("3-letter");
X    } elsif ($curline =~ / Invalid city or state code./) {
X	printf SOCK "X\n";
X	printf "%s is an invalid city or state code.\n", $CITY;
X	&showitoff("invalid");
X    } elsif ($curline =~ / CITY FORECAST MENU/) {
X	&showitoff("city forecast");
X    } elsif ($curline =~ / CURRENT WEATHER MENU/) {
X	&showitoff("city forecast");
X    } elsif ($curline =~ / CANADIAN FORECASTS/) {
X	&showitoff("canadian forecasts");
X    } elsif ($curline =~ / Press Return to continue: /) {
X	printf SOCK "\n";
X	$curline = "";
X	&showiton("Return to continue");
X    } elsif ($curline =~ / Press Return to continue printing or M to return to menu: /) {
X	printf SOCK "\n";
X	$curline = "";
X	&showiton("Return to continue printing");
X    } elsif ($curline =~ / Press Return to display statement, M for menu: /) {
X	# kenr@storage.tandem.com: Handle severe weather statement in city
X        printf SOCK "\n";
X        $curline = "";
X        &showiton("Return to display statment (city)");
X    } elsif ($curline =~ / Press [rR]eturn to display statement, M to display main menu: /) {
X	# gf: Similarly for severe Michigan weather and Canadian forecasts
X	if ($ISCAN) {
X	    printf SOCK "M\n";
X	    &showitoff("Return to display statement (main)");
X	} else {
X	    printf SOCK "\n";
X	    &showiton("Return to display statement (main)");
X	}
X        $curline = "";
X    }
X}
X
X#
X# Clean up and done
X#
Xclose(SOCK);
Xexit(0);
X
X#####################################################
X
Xsub getaddress {
X    local($host) = @_;
X    local(@ary);
X    @ary = gethostbyname($host);
X    return(unpack("C4",$ary[4]));
X}
X
Xsub showitoff {
X    local($txt) = @_;
X    &maybeprint ("showit off ($txt)\n");
X    $SHOWIT = 0;
X}
X
Xsub showiton {
X    local($txt) = @_;
X    &maybeprint ("showit on ($txt)\n");
X    $SHOWIT = 1;
X}
X
Xsub maybeprint {
X#    print @_;
X}
END_OF_FILE
if test 7183 -ne `wc -c <'weather.pl'`; then
    echo shar: \"'weather.pl'\" unpacked with wrong size!
fi
# end of 'weather.pl'
fi
if test -f 'weatherT.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'weatherT.man'\"
else
echo shar: Extracting \"'weatherT.man'\" \(2996 characters\)
sed "s/^X//" >'weatherT.man' <<'END_OF_FILE'
X.\" This is "weatherT.man", used to generate "weather.man".
X.TH WEATHER 1 "30 Jun 1992"
X.SH NAME
Xweather - display current weather for a city or state
X.SH SYNOPSIS
X.B "weather"
X[city, state, or canadian zone code]
X.SH DESCRIPTION
X.PP
X.I Weather
Xis program that will print the current weather conditions for an area.
X.I Weather
Xis a Perl(1) script that connects to the Weather Underground weather 
Xserver from The University of Michigan, sends the appropriate request,
Xignores the inappropriate text, and prints out the weather data.
X.PP
XIf no code is given on the command-line, then the forecast for the
Xdefault city (<<DEFCITY>>) is retrieved.
X.SH OPTIONS
X.TP
X.B city code
XThe 3 letter airport style city code will cause
X.I weather
Xto display the weather for that specified city. The weather server
Xcan display the city codes for a given state using the interactive
Xinterface described below.
X.TP
X.B state code
XThe 2 letter state abbreviation will cause
X.I weather
Xto display (a brief version of) the current weather 
Xfor that specified state.
X.TP
X.B Canadian zone code
XThe following list of codes are understood for Canadian weather reports:
X
X.nf
X.na
X  1.  SALT (Southern Alberta)      11 LABR (Labrador)
X  2.  NALT (Northern Alberta)      12 NFLD (Newfoundland)
X  3.  NALT|NEBC (N. Alta - NE BC)  13 SONT (Southern Ontario)
X  4.  COBC (Coastal BC)            14 NONT (Northern Ontario)
X  5.  INBC (Interior BC)           15 NWON (Northwest Ontario)
X  6.  SMAN (Southern Manitoba)     16 SSAS (Southern Saskatchewan)
X  7.  NMAN (Northern Manitoba)     17 NSAS (Northern Saskatchewan)
X  8.  NOVA (Nova Scotia)           18 YUKN (Yukon)
X  9.  PEDI (Prince Edward Island)  19 SQUE|OTTW (S. Quebec - Ottawa)
X  10. NEWB (New Brunswick)         20 NQUE (Northern Quebec)
X
X.ad
X.fi
XA vertical bar (`|') denotes alternate names for the region.  Either
Xthe four-character symbolic name (in upper- or lowercase) or the zone
Xnumber can be given to
X.IR weather .
X.SH "WEATHER SERVER"
XThe Weather Underground provides more detailed information using an
Xinteractive interface than can be extracted automatically by this
Xscript. Use the command
X
X.ce
X% telnet <<SERVERHOST>> <<SERVERPORT>>
X
Xto connect interactively. Please limit your connection time to help
Xlower server load.
X.SH BUGS
XEvery time the menus on the server changes, 
X.I weather 
Xwill usually wind up hanging, or printing the same
Xtext infinitely.
X.PP
XPlease *don't* send me mail if this happens. If I update the script
Xyou can be sure I will post the changes. However, please do not mail
Xme requesting new versions. The Perl script is simple enough for you
Xto have a go at fixing it yourself and posting the changes. Both the
XNet and I will love you for it.
X.SH SEE ALSO
Xxforecast(1),
XPerl(1)
X.SH AUTHOR
X.na
XFrank Adelstein, frank@cis.ohio-state.edu.
X.PP
XCanadian support added by George Ferguson, ferguson@cs.rochester.edu.
X.PP
XUpdated for new weather server menus by George Ferguson, 26 Jun 1992.
X.SH COPYRIGHT
XCopyright 1991, Frank Adelstein.
END_OF_FILE
if test 2996 -ne `wc -c <'weatherT.man'`; then
    echo shar: \"'weatherT.man'\" unpacked with wrong size!
fi
# end of 'weatherT.man'
fi
if test -f 'weather.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'weather.man'\"
else
echo shar: Extracting \"'weather.man'\" \(2927 characters\)
sed "s/^X//" >'weather.man' <<'END_OF_FILE'
X.TH WEATHER 1 "30 Jun 1992"
X.SH NAME
Xweather - display current weather for a city or state
X.SH SYNOPSIS
X.B "weather"
X[city, state, or canadian zone code]
X.SH DESCRIPTION
X.PP
X.I Weather
Xis program that will print the current weather conditions for an area.
X.I Weather
Xis a Perl(1) script that connects to the Weather Underground weather 
Xserver from The University of Michigan, sends the appropriate request,
Xignores the inappropriate text, and prints out the weather data.
X.PP
XIf no code is given on the command-line, then the forecast for the
Xdefault city (ROC) is retrieved.
X.SH OPTIONS
X.TP
X.B city code
XThe 3 letter airport style city code will cause
X.I weather
Xto display the weather for that specified city. The weather server
Xcan display the city codes for a given state using the interactive
Xinterface described below.
X.TP
X.B state code
XThe 2 letter state abbreviation will cause
X.I weather
Xto display (a brief version of) the current weather 
Xfor that specified state.
X.TP
X.B Canadian zone code
XThe following list of codes are understood for Canadian weather reports:
X
X.nf
X.na
X  1.  SALT (Southern Alberta)      11 LABR (Labrador)
X  2.  NALT (Northern Alberta)      12 NFLD (Newfoundland)
X  3.  NALT|NEBC (N. Alta - NE BC)  13 SONT (Southern Ontario)
X  4.  COBC (Coastal BC)            14 NONT (Northern Ontario)
X  5.  INBC (Interior BC)           15 NWON (Northwest Ontario)
X  6.  SMAN (Southern Manitoba)     16 SSAS (Southern Saskatchewan)
X  7.  NMAN (Northern Manitoba)     17 NSAS (Northern Saskatchewan)
X  8.  NOVA (Nova Scotia)           18 YUKN (Yukon)
X  9.  PEDI (Prince Edward Island)  19 SQUE|OTTW (S. Quebec - Ottawa)
X  10. NEWB (New Brunswick)         20 NQUE (Northern Quebec)
X
X.ad
X.fi
XA vertical bar (`|') denotes alternate names for the region.  Either
Xthe four-character symbolic name (in upper- or lowercase) or the zone
Xnumber can be given to
X.IR weather .
X.SH "WEATHER SERVER"
XThe Weather Underground provides more detailed information using an
Xinteractive interface than can be extracted automatically by this
Xscript. Use the command
X
X.ce
X% telnet downwind.sprl.umich.edu 3000
X
Xto connect interactively. Please limit your connection time to help
Xlower server load.
X.SH BUGS
XEvery time the menus on the server changes, 
X.I weather 
Xwill usually wind up hanging, or printing the same
Xtext infinitely.
X.PP
XPlease *don't* send me mail if this happens. If I update the script
Xyou can be sure I will post the changes. However, please do not mail
Xme requesting new versions. The Perl script is simple enough for you
Xto have a go at fixing it yourself and posting the changes. Both the
XNet and I will love you for it.
X.SH SEE ALSO
Xxforecast(1),
XPerl(1)
X.SH AUTHOR
X.na
XFrank Adelstein, frank@cis.ohio-state.edu.
X.PP
XCanadian support added by George Ferguson, ferguson@cs.rochester.edu.
X.PP
XUpdated for new weather server menus by George Ferguson, 26 Jun 1992.
X.SH COPYRIGHT
XCopyright 1991, Frank Adelstein.
END_OF_FILE
if test 2927 -ne `wc -c <'weather.man'`; then
    echo shar: \"'weather.man'\" unpacked with wrong size!
fi
# end of 'weather.man'
fi
echo shar: End of shell archive.
exit 0

-- 
George Ferguson                 ARPA: ferguson@cs.rochester.edu
Dept. of Computer Science       UUCP: rutgers!rochester!ferguson
University of Rochester         VOX:  (716) 275-2527
Rochester  NY  14627-0226       FAX:  (716) 461-2018


