Subject: getduatweather - a Perl script to grab the current pilot weather

From: [email-masked] (Randal L. Schwartz)
Date: 20 Jan 92 23:01:52 GMT

Thanks to Geoff Peck's updated script, which pointed out to me a few
new things about duat.contel.com, I updated my weather script to run
much faster using Contel's new Quick Path (tm).  It now also no longer
needs to be run by a valid pilot, again thanks to Contel.

If you are not a pilot, the weather may not make much sense to you
(and no, I'm not in the business of explaining it, sorry...).  But if
you know how to interpret pilot weather, and can get the three letter
identifier for the US airport you are interested in, this program gets
you access to the NWS weather database.

This script requires Perl 4.019 (which has my chat2.pl in the
library), or a copy of chat2.pl from the archives.  It does *not*
require a working "telnet" program, as the Perl program is doing all
the TCP-ing.

By default, it gets the "wt" and "ft" values for "hio" (Hillsboro
Airport, just down the street from where I typed this message).  The
first parameter is an airport, or list of comma-separated airports (to
replace "hio").  The second parameter is a comma-separated list of
weather products (to replace "wt,ft").  A "-d" flag before any other
parameter allows you to follow along for debugging (or if you are just
curious about what it is doing).  You'll probably want to edit the
lines that set $where and $what so that your favorite defaults are
selected instead.

Enjoy!

[Please be careful on the followups... comp.lang.perl and rec.aviation
normally don't overlap much. :-]

#! /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:  getduatweather
# Wrapped by [email-masked] on Mon Jan 20 14:57:05 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'getduatweather' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'getduatweather'\"
else
echo shar: Extracting \"'getduatweather'\" \(2448 characters\)
sed "s/^X//" >'getduatweather' <<'END_OF_FILE'
X#!/usr/bin/perl
X
X# push(@INC, '/local/merlyn/lib/perl');
X
Xrequire 'chat2.pl';
X
Xshift, $| = $trace = 1 if $ARGV[0] =~ /^-d/; # debug mode
X
X$where = shift || "hio";
X$what = shift || "wt,ft";
X
X&chat'open_port('duat.contel.com', 23) || die "open: $!";
Xdie "wanted open, got $_"
X	unless ($_ = &listenr(20, 'last name:')) =~ /DUAT access code/i;
X&talk("Turing :-)\r");
Xdie "wanted first name, got $_"
X	unless ($_ = &listenr(20, 'first name:')) =~ /first name/i;
X&talk("getduatweather_by_Randal_L_Schwartz_(503)777-0095\r");
Xdie "wanted middle initial, got $_"
X	unless ($_ = &listenr(20, 'middle initial:')) =~ /middle initial/i;
X&talk("A\r");
Xdie "wanted certification number, got $_"
X	unless ($_ = &listenr(20, 'certification number:')) =~ /certification number/i;
X&talk("\r");
Xdie "wanted 20 to 99, got $_"
X	unless ($_ = &listenr(20, '20 to 99:')) =~ /20 to 99/i;
X&talk("80\r");
Xdie "wanted 0 .constant scroll. to 99, got $_"
X	unless ($_ = &listenr(20, '0 .constant scroll. to 99:')) =~ /to 99/i;
X&talk("0\r");
Xdie "wanted RETURN to continue, got $_"
X	unless ($_ = &listenr(20, 'RETURN to continue')) =~ /RETURN to con/i;
X&talk("\r");
Xdie "wanted main menu, got $_"
X	unless ($_ = &listenr(20, '\):')) =~ /weather briefing\s+(\d)/i;
X$later = sprintf("%02d59",(gmtime)[2]);
X&talk("#PSES\\P\\$where\\$what\\$later\\\r");
X$_ = &listenr(20, 'quit\):');
Xdie "wanted q to quit, got $_"
X	unless /'q' to quit/i;
Xs/\r//g;
Xs/^(.*\n)*.*time zone selected.*\s+//;
Xs/\s+\S.*Main Menu(.|\n)+//;
X$weather = $_; # should process this
X&talk("#BYE\\y\r");
X&listen(20); # for trace
X
X&chat'close();
Xprint $weather, "\n";
Xexit(0);
X
X
Xsub talk {
X	local($text) = @_;
X	print "{$text}" if $trace;
X	&chat'print($text);
X}
X
Xsub listen {
X	local($secs) = @_;
X	local($return,$tmp) = "";
X	while (length($tmp = &telnet_read($secs))) {
X		print $tmp if $trace;
X		$return .= $tmp;
X	}
X	$return;
X}
X
Xsub listenr {
X	local($secs,$regex) = @_;
X	local($return,$tmp) = "";
X	while (length($tmp = &telnet_read($secs))) {
X		print $tmp if $trace;
X		$return .= $tmp;
X		last if $return =~ /$regex/i;
X	}
X	$return;
X}
X
Xsub telnet_read {
X	local($secs) = @_;
X	&chat'expect($secs,
X		'^\377[\375\376](.|\n)',
X		q#&chat'print ("\377\374".$1); redo LOOP#,
X			# WON'T do these do/don't requests
X		'^\377[\373\374](.|\n)', 'redo LOOP',
X			# ignore these will/won't changes
X		'^\377\377', '"\377"',
X			# escaping the IAC
X		'^\377(.|\n)', 'redo LOOP',
X			# ignoring these
X		'^[^\377]+', '$&'
X			# return these
X		);
X}
END_OF_FILE
if test 2448 -ne `wc -c <'getduatweather'`; then
    echo shar: \"'getduatweather'\" unpacked with wrong size!
fi
chmod +x 'getduatweather'
# end of 'getduatweather'
fi
echo shar: End of shell archive.
exit 0
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| [email-masked] ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/

---

From: <[email-masked]>
Date: Tuesday, 28 Jan 1992 22:58:11 CST

Here in No Dak country, where men are Pilots and Women are dinosaurs...
We use the same communications software to call Pan Am WeaterMation and
get the same typed aviation reports. Of course we all know we could call
1-800-WX-BRIEF or 1-800-992-7433. The only thing I can not do from my dorm
room is file a flight plan via this software. If I spent $185 to get the
software from Pan Am WeatherMation, I could file flight plans and get
printed maps. I have the Jepp Duat program, but these cost like 20 cents
per minute of connect time. Pan Am is free for just the written format.
Harry, KB0BUQ,WNHZ-241, CA,IRA,BGI,AGI,IGI,ASEL,ASES,AMEL.
And now working on C-500 type rating...