home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!psgrain!neon!jeff
- From: jeff@neon.rain.com (Jeff Beadles)
- Newsgroups: or.general
- Subject: Re: Looking for online weather reports
- Message-ID: <BxKwA6.rs@neon.rain.com>
- Date: 12 Nov 92 01:03:41 GMT
- Article-I.D.: neon.BxKwA6.rs
- References: <BxKApw.Kqr@hfglobe.intel.com>
- Reply-To: jeff@onion.rain.com (Jeff Beadles)
- Distribution: or
- Lines: 384
-
- snelson@ptdca2.intel.com (Shannon Nelson) writes:
-
- >Someone mentioned once that there's a machine at orst.edu that has
- >online weather reports available through finger. Is this service
- >still available? If so, what is the address to be finger'd?
-
- Or, if you want weather all around the world, you can telnet to
- downwind.sprl.umich.edu on port 3000. You can do this by issuing
- the command:
- %> telnet downwind.sprl.umich.edu 3000
-
- The city code for Portland is "PDX"
-
- from any properly configured host that is Internet connected.
-
- The output looks like:
-
- PORTLAND METROPOLITAN AREA FORECAST
- NATIONAL WEATHER SERVICE PORTLAND OR
- 345 PM PST WED NOV 11 1992
-
- TONIGHT...RAIN AT TIMES. LOWS 40 TO 45. SOUTHEAST WIND 10 MPH.
- THURSDAY...RAIN TAPERING OFF. HIGHS IN MID 50S. SOUTHEAST WIND 5 TO 15 MPH.
- THURSDAY NIGHT...LOW CLOUDS AND FOG. LOWS 35 TO 45.
- FRIDAY...LOW CLOUDS AND FOG SLOWLY DISSIPATING. HIGHS MID 50S.
-
- CHANCE OF MEASURABLE RAIN DECREASING TO 30 PERCENT THURSDAY.
-
- ...
-
- Attached is a perl script that was posted to the net a while back that
- automagically will do this for you. It's probably not the most current
- version, but it works for me.
-
-
- -Jeff
- --
- Jeff Beadles jeff@onion.rain.com
-
-
-
- #--------------------------------CUT HERE-------------------------------------
- #! /bin/sh
- #
- # This is a shell archive. Save this into a file, edit it
- # and delete all lines above this comment. Then give this
- # file to sh by executing the command "sh file". The files
- # will be extracted into the current directory owned by
- # you with default permissions.
- #
- # The files contained herein are:
- #
- # -rwxr-xr-x 1 jeff 9415 Nov 11 17:02 weather
- #
- echo 'x - weather'
- if test -f weather; then echo 'shar: not overwriting weather'; else
- sed 's/^X//' << '________This_Is_The_END________' > weather
- X#!/usr/bin/perl
- X'di';
- X'ig00';
- 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# Modified by gf for new weather service menus, 26 Jun 1992.
- 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#
- X# Modified by rouilj@cs.umb.edu October 9, 1992. Changed pattern to
- X# match almost all "type return to continue" type lines. Hopefully the
- X# entire report will be presented to the user now. Also added flags
- X# that allow selection of the info to get from the weather server. In
- X# addition added code that makes use of the menu bypass ability, and
- X# allows supression of the 24 line scroll restriction. Added the -q
- X# flag that can be used to list (query) the three letter abbreviations
- X# for all weather reporting sites within a state. In addition changed
- X# the default city to be Boston ;-). Also crafted (crufted??) together
- X# a rudimentary man page, and encapsulated it into the weather script.
- X
- Xrequire "getopts.pl";
- X
- X$SERVER = "downwind.sprl.umich.edu";
- X$PORT = "3000";
- X
- X$show_what = "+"; # this turns off the 24 line scroll restriction.
- X
- X#
- X# Parse argument, if any
- X#
- X&Getopts("ufcemsqD");
- X
- X$CITY = $ARGV[0];
- Xif ($CITY eq "") {
- X $CITY = "pdx"; # THIS IS THE DEFAULT CITY!!!!!!!!!!!
- X}
- X
- Xif (defined($opt_q)) {
- X die "Can only use 2 letter state abbreviations with -q, exited"
- X if (length($CITY) > 2);
- X}
- X
- X$whichinfo_opts++, $show_what = "u" if defined($opt_u);
- X$whichinfo_opts++, $show_what = "f" if defined($opt_f);
- X$whichinfo_opts++, $show_what = "c" if defined($opt_c);
- X$whichinfo_opts++, $show_what = "e" if defined($opt_e);
- X$whichinfo_opts++, $show_what = "m" if defined($opt_m);
- X$whichinfo_opts++, $show_what = "s" if defined($opt_s);
- X
- Xdie "Only one of -ufcems can be used, exiting" if $whichinfo_opts > 1;
- 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$USMENU = 0; # See US 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 print $curline . "\n" if defined($opt_D);
- 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 } elsif (defined($opt_q)) {
- X printf SOCK "\n"; # For query, go via main menu
- X } else {
- X printf SOCK "%s%s\n", $CITY, $show_what; # 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 } elsif (defined $opt_q) {
- X if (!$MAINMENU) { # At main menu, select Canadian forecasts
- X $MAINMENU = 1;
- X printf SOCK "1\n"; # US menu is item 1!!
- X $curline = "";
- X } elsif (!$USMENU) { # At Canadian menu, select region
- X $USMENU = 1;
- X printf SOCK "3\n";
- 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 =~ / Enter 2-letter state code: /) {
- X printf SOCK "%s\n", $CITY;
- X &showiton("Weather Sites");
- 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}
- X
- X###############################################################
- X
- X # These next few lines are legal in both Perl and nroff.
- X
- X.00; # finish .ig
- X
- X'di \" finish diversion--previous line must be blank
- X.nr nl 0-1 \" fake up transition to first page again
- X.nr % 0 \" start at page 1
- X'; __END__ ##### From here on it's a standard manual page #####
- X.TH WEATHER 1 "October 9, 1992"
- X.SH NAME
- Xweather \- query the weather server for weather info
- X.SH SYNOPSIS
- X.B weather
- X.RB [ \-ufcems ]
- X[ three_letter_city_code ]
- X.PP
- X.B weather
- X.RB [ \-q ]
- Xtwo_letter_state_code
- X.PP
- X.SH DESCRIPTION
- XThis command queries the weather database server run by the University
- Xof Michigan. By default it gets the weather service report for the
- XBoston, Massachusetts area.
- X.PP
- XThe arguments it takes are a US state abbreviation, or a three letter
- XUS Weather Service site abbreviation. If given a state abbreviation,
- Xthe regional weather information is provided. If given a three letter
- Xsite abbreviation, a weather report usually consisting of the 1-2 day
- Xforecast, the extended forecast, any special weather advisories, and
- Xclimatic data is presented. Some of the above sections may not be
- Xavailable for a given weather site. The options can be used to select
- Xsubsets of the presented data.
- X.IP
- X.B \-u
- XThis option eliminates the climate data from the report.
- X.IP
- X.B \-f
- XRestricts the output to the 1-2 day forcast.
- X.IP
- X.B \-c
- XProvide only the climatic data.
- X.IP
- X.B \-e
- XProvide only the extended forcast data.
- X.IP
- X.B \-s
- XProvide only the special advisory reports.
- X.IP
- X.B \-m
- XProvide the marine report if available.
- X.IP
- X.B \-q
- XThis option can only be used with a two letter state abbreviation, and
- Xit produces a list of all of the three letter site codes for the
- Xstate.
- X.PP
- XThe entire program is written in perl.
- X.SH ENVIRONMENT
- XNo environment variables are used.
- X.SH FILES
- XNone.
- X.SH "SEE ALSO"
- Xperl(1).
- X
- ________This_Is_The_END________
- if test `wc -c < weather` -ne 9415; then
- echo 'shar: weather was damaged during transit (should have been 9415 bytes)'
- fi
- fi ; : end of overwriting check
- exit 0
-