home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / or / general / 709 < prev    next >
Encoding:
Internet Message Format  |  1992-11-11  |  11.8 KB

  1. Path: sparky!uunet!ogicse!psgrain!neon!jeff
  2. From: jeff@neon.rain.com (Jeff Beadles)
  3. Newsgroups: or.general
  4. Subject: Re: Looking for online weather reports
  5. Message-ID: <BxKwA6.rs@neon.rain.com>
  6. Date: 12 Nov 92 01:03:41 GMT
  7. Article-I.D.: neon.BxKwA6.rs
  8. References: <BxKApw.Kqr@hfglobe.intel.com>
  9. Reply-To: jeff@onion.rain.com (Jeff Beadles)
  10. Distribution: or
  11. Lines: 384
  12.  
  13. snelson@ptdca2.intel.com (Shannon Nelson) writes:
  14.  
  15. >Someone mentioned once that there's a machine at orst.edu that has
  16. >online weather reports available through finger.  Is this service
  17. >still available?  If so, what is the address to be finger'd?
  18.  
  19. Or, if you want weather all around the world, you can telnet to
  20. downwind.sprl.umich.edu on port 3000.  You can do this by issuing
  21. the command:
  22.   %> telnet downwind.sprl.umich.edu 3000
  23.  
  24. The city code for Portland is "PDX"
  25.  
  26. from any properly configured host that is Internet connected.
  27.  
  28. The output looks like:
  29.  
  30. PORTLAND METROPOLITAN AREA FORECAST
  31. NATIONAL WEATHER SERVICE PORTLAND OR
  32. 345 PM PST WED NOV 11 1992
  33.  
  34.  TONIGHT...RAIN AT TIMES. LOWS 40 TO 45. SOUTHEAST WIND 10 MPH.
  35.  THURSDAY...RAIN TAPERING OFF. HIGHS IN MID 50S. SOUTHEAST WIND 5 TO 15 MPH.
  36.  THURSDAY NIGHT...LOW CLOUDS AND FOG. LOWS 35 TO 45.
  37.  FRIDAY...LOW CLOUDS AND FOG SLOWLY DISSIPATING. HIGHS MID 50S.
  38.  
  39. CHANCE OF MEASURABLE RAIN DECREASING TO 30 PERCENT THURSDAY.
  40.  
  41. ...
  42.  
  43. Attached is a perl script that was posted to the net a while back that
  44. automagically will do this for you.  It's probably not the most current
  45. version, but it works for me.
  46.  
  47.  
  48.     -Jeff
  49. -- 
  50. Jeff Beadles        jeff@onion.rain.com
  51.  
  52.  
  53.  
  54. #--------------------------------CUT HERE-------------------------------------
  55. #! /bin/sh
  56. #
  57. # This is a shell archive.  Save this into a file, edit it
  58. # and delete all lines above this comment.  Then give this
  59. # file to sh by executing the command "sh file".  The files
  60. # will be extracted into the current directory owned by
  61. # you with default permissions.
  62. #
  63. # The files contained herein are:
  64. #
  65. # -rwxr-xr-x  1 jeff         9415 Nov 11 17:02 weather
  66. #
  67. echo 'x - weather'
  68. if test -f weather; then echo 'shar: not overwriting weather'; else
  69. sed 's/^X//' << '________This_Is_The_END________' > weather
  70. X#!/usr/bin/perl
  71. X'di';
  72. X'ig00';
  73. X#
  74. X# A perl script to connect to the 'weather server' at
  75. X# Michigan and get the forcast for whatever city
  76. X# you want (3 letter code -- columbus 'cmh' by default).
  77. X#
  78. X# Alternatively, you can get the current information for
  79. X# a state if you enter a 2 letter code.
  80. X#
  81. X# Thanks to J Greely for the original network code, and
  82. X# Tom Fine for assistance and harassment.
  83. X#
  84. X# Copyright 1991 Frank Adelstein.  All Rights Reserved.
  85. X#
  86. X# Permission to use, copy, modify, and distribute this
  87. X# software is hereby granted without fee, provided that
  88. X# the copyright notice and permission notice are not removed.
  89. X#
  90. X# --FNA 6/28/91
  91. X#
  92. X# Hacked by George Ferguson (ferguson@cs.rochester.edu) to include
  93. X# Canadian forecasts by zone number.
  94. X#
  95. X# Modified by gf for new weather service menus, 26 Jun 1992.
  96. X# I ripped lots of stuff out of this version, some of it may have to be
  97. X# put back, but it works fine for me.
  98. X# It's much easier to navigate the system now (for US forecasts, anyway),
  99. X# so the interaction loop is considerably simplified. The Canadian stuff
  100. X# is relatively straightforward also.
  101. X#
  102. X# Modified by rouilj@cs.umb.edu October 9, 1992.  Changed pattern to
  103. X# match almost all "type return to continue" type lines. Hopefully the
  104. X# entire report will be presented to the user now. Also added flags
  105. X# that allow selection of the info to get from the weather server. In
  106. X# addition added code that makes use of the menu bypass ability, and
  107. X# allows supression of the 24 line scroll restriction. Added the -q
  108. X# flag that can be used to list (query) the three letter abbreviations
  109. X# for all weather reporting sites within a state.  In addition changed
  110. X# the default city to be Boston ;-). Also crafted (crufted??) together
  111. X# a rudimentary man page, and encapsulated it into the weather script.
  112. X
  113. Xrequire "getopts.pl";
  114. X
  115. X$SERVER = "downwind.sprl.umich.edu";
  116. X$PORT   = "3000";
  117. X
  118. X$show_what = "+"; # this turns off the 24 line scroll restriction.
  119. X
  120. X#
  121. X# Parse argument, if any
  122. X#
  123. X&Getopts("ufcemsqD");
  124. X
  125. X$CITY = $ARGV[0]; 
  126. Xif ($CITY eq "") {
  127. X    $CITY = "pdx";        # THIS IS THE DEFAULT CITY!!!!!!!!!!!
  128. X}
  129. X
  130. Xif (defined($opt_q)) {
  131. X  die "Can only use 2 letter state abbreviations with -q, exited"
  132. X            if (length($CITY) > 2);
  133. X}
  134. X
  135. X$whichinfo_opts++, $show_what = "u" if defined($opt_u);
  136. X$whichinfo_opts++, $show_what = "f" if defined($opt_f);
  137. X$whichinfo_opts++, $show_what = "c" if defined($opt_c);
  138. X$whichinfo_opts++, $show_what = "e" if defined($opt_e);
  139. X$whichinfo_opts++, $show_what = "m" if defined($opt_m);
  140. X$whichinfo_opts++, $show_what = "s" if defined($opt_s);
  141. X
  142. Xdie "Only one of -ufcems can be used, exiting" if $whichinfo_opts > 1;
  143. X
  144. X#
  145. X# Allow 4-char symbolic names for Canadian reports.
  146. X#
  147. X%canNames = ("salt","1",  "SALT","1",
  148. X         "calt","2",  "CALT","2",
  149. X         "nalt","3",  "NALT","3", "nebc","3", "NEBC","3",
  150. X         "cobc","4",  "COBC","4",
  151. X         "inbc","5",  "INBC","5",
  152. X         "sman","6",  "SMAN","6",
  153. X         "nman","7",  "NMAN","7",
  154. X         "nova","8",  "NOVA","8",
  155. X         "pedi","9",  "PEDI","9",
  156. X         "newb","10", "NEWB","10",
  157. X         "labr","11", "LABR","11",
  158. X         "nfld","12", "NFLD","12",
  159. X         "sont","13", "SONT","13",
  160. X         "nont","14", "NONT","14",
  161. X         "nwon","15", "NWON","15",
  162. X         "ssas","16", "SSAS","16",
  163. X         "nsas","17", "NSAS","17",
  164. X         "yukn","18", "YUKN","18",
  165. X         "sque","19", "SQUE","19", "ottw","19", "OTTW","19",
  166. X         "nque","20", "NQUE","20");              
  167. X#
  168. X# If we're given one of these names, use the number instead.
  169. X#
  170. Xif ($t=$canNames{$CITY}) {
  171. X    $CITY = $t;
  172. X}
  173. X
  174. X#
  175. X# Check argument
  176. X#
  177. Xif ($CITY =~ /[0-9]+/) {
  178. X    $ISCAN = 1;
  179. X} elsif (length ($CITY) == 3 ) {
  180. X    $ISCAN = 0;
  181. X} elsif (length ($CITY) == 2 ) {
  182. X    $ISCAN = 0;
  183. X} else {
  184. X    print "Must be either a 2 letter state code or 3 letter city code.\n";
  185. X    print "Can also be a numeric Canadian zone number or symbolic name.\n";
  186. X    exit (1);
  187. X}
  188. X
  189. X#
  190. X# Connect to the server
  191. X#
  192. Xlocal($sockaddr,$here,$there,$response,$tries) = ("Snc4x8");
  193. X$here  = pack($sockaddr,2,0,&getaddress("localhost"));
  194. X$there = pack($sockaddr,2,$PORT,&getaddress($SERVER));
  195. Xprint "\nConnecting to $SERVER.";
  196. Xdie "socket: $!\n" if (!socket(SOCK,2,1,6));
  197. Xprint ".";
  198. Xdie "connect: $!\n" if (!connect(SOCK,$there));
  199. Xprint ".connected\n";
  200. Xselect(SOCK); $| = 1;
  201. Xselect(STDOUT); $| = 1;       # make unbuffered
  202. X
  203. X#
  204. X# Initialize
  205. X#
  206. X$SHOWIT = 0;            # Should we print?
  207. X$MAINMENU = 0;            # Seen main menu once already?
  208. X$CANMENU = 0;            # See Canadian menu once already?
  209. X$USMENU = 0;            # See US menu once already?
  210. X
  211. X#
  212. X# Interact...
  213. X#
  214. Xwhile (read(SOCK,$c,1)) {    # Get a character
  215. X    if ($c eq "\n") {        # Newline -> maybe print, start new line
  216. X    if ($SHOWIT == 1) {
  217. X        print $curline, "\n";
  218. X    }
  219. X    $curline = "";
  220. X    next; 
  221. X    }
  222. X    if ($c eq "\r") { next; }    # Return -> ignore
  223. X    $curline .= $c;        # Else add char to current line
  224. X    print $curline . "\n" if defined($opt_D);
  225. X    
  226. X    #
  227. X    # Now test the current line so far to see what action to take, if any.
  228. X    #
  229. X    if ($curline =~ /Press Return for menu, or enter 3 letter forecast city code:/) { # At first prompt...
  230. X    if ($ISCAN) {
  231. X        printf SOCK "\n";    # For Canadian forecast, go via main menu
  232. X    } elsif (defined($opt_q)) {
  233. X        printf SOCK "\n";    # For query, go via main menu
  234. X    } else {
  235. X        printf SOCK "%s%s\n", $CITY, $show_what; # For US, bypass menu
  236. X        $curline = "";
  237. X        &showiton("us city/state");
  238. X    }
  239. X    } elsif ($curline =~ / Selection:/) { # In main menu...
  240. X    if ($ISCAN) {        # Canadian forecast...
  241. X        if (!$MAINMENU) {        # At main menu, select Canadian forecasts
  242. X        $MAINMENU = 1;
  243. X        printf SOCK "2\n";  # Canadian forecast is item 2!!
  244. X        $curline = "";
  245. X        } elsif (!$CANMENU) {   # At Canadian menu, select region
  246. X        $CANMENU = 1;
  247. X        printf SOCK "%s\n", $CITY;
  248. X        &showiton("canadian region");
  249. X        $curline = "";
  250. X        } else {
  251. X        printf SOCK "X\n";  # Otherwise exit
  252. X        }
  253. X    } elsif (defined $opt_q) {
  254. X        if (!$MAINMENU) {        # At main menu, select Canadian forecasts
  255. X        $MAINMENU = 1;
  256. X        printf SOCK "1\n";  # US menu is item 1!!
  257. X        $curline = "";
  258. X        } elsif (!$USMENU) {   # At Canadian menu, select region
  259. X        $USMENU = 1;
  260. X        printf SOCK "3\n";
  261. X        $curline = "";
  262. X        } else {
  263. X        printf SOCK "X\n";  # Otherwise exit
  264. X        }
  265. X    } else {
  266. X        printf SOCK "X\n";    # Otherwise exit
  267. X    }
  268. X    } elsif ($curline =~ / Invalid 3-letter city code./) {
  269. X    printf SOCK "X\n";
  270. X    printf "%s is an invalid 3 letter city code.\n", $CITY;
  271. X    &showitoff("3-letter");
  272. X    } elsif ($curline =~ / Invalid city or state code./) {
  273. X    printf SOCK "X\n";
  274. X    printf "%s is an invalid city or state code.\n", $CITY;
  275. X    &showitoff("invalid");
  276. X    } elsif ($curline =~ / CITY FORECAST MENU/) {
  277. X    &showitoff("city forecast");
  278. X    } elsif ($curline =~ / CURRENT WEATHER MENU/) {
  279. X    &showitoff("city forecast");
  280. X    } elsif ($curline =~ / CANADIAN FORECASTS/) {
  281. X    &showitoff("canadian forecasts");
  282. X    } elsif ($curline =~ / Press Return to continue,.*: /) {
  283. X    printf SOCK "\n";
  284. X    $curline = "";
  285. X    &showiton("Return to continue");
  286. X    } elsif ($curline =~ /          Enter 2-letter state code: /) {
  287. X        printf SOCK "%s\n", $CITY;
  288. X        &showiton("Weather Sites");
  289. X        $curline = "";
  290. X    }
  291. X}
  292. X
  293. X#
  294. X# Clean up and done
  295. X#
  296. Xclose(SOCK);
  297. Xexit(0);
  298. X
  299. X#####################################################
  300. X
  301. Xsub getaddress {
  302. X    local($host) = @_;
  303. X    local(@ary);
  304. X    @ary = gethostbyname($host);
  305. X    return(unpack("C4",$ary[4]));
  306. X}
  307. X
  308. Xsub showitoff {
  309. X    local($txt) = @_;
  310. X    &maybeprint ("showit off ($txt)\n");
  311. X    $SHOWIT = 0;
  312. X}
  313. X
  314. Xsub showiton {
  315. X    local($txt) = @_;
  316. X    &maybeprint ("showit on ($txt)\n");
  317. X    $SHOWIT = 1;
  318. X}
  319. X
  320. Xsub maybeprint {
  321. X#    print @_;
  322. X}
  323. X
  324. X###############################################################
  325. X
  326. X    # These next few lines are legal in both Perl and nroff.
  327. X
  328. X.00;                       # finish .ig
  329. X'di           \" finish diversion--previous line must be blank
  330. X.nr nl 0-1    \" fake up transition to first page again
  331. X.nr % 0         \" start at page 1
  332. X'; __END__ ##### From here on it's a standard manual page #####
  333. X.TH WEATHER 1 "October 9, 1992"
  334. X.SH NAME
  335. Xweather \- query the weather server for weather info
  336. X.SH SYNOPSIS
  337. X.B weather
  338. X.RB [ \-ufcems ]
  339. X[ three_letter_city_code ]
  340. X.PP
  341. X.B weather
  342. X.RB [ \-q ]
  343. Xtwo_letter_state_code
  344. X.PP
  345. X.SH DESCRIPTION
  346. XThis command queries the weather database server run by the University
  347. Xof Michigan. By default it gets the weather service report for the
  348. XBoston, Massachusetts area.
  349. X.PP
  350. XThe arguments it takes are a US state abbreviation, or a three letter
  351. XUS Weather Service site abbreviation. If given a state abbreviation,
  352. Xthe regional weather information is provided. If given a three letter
  353. Xsite abbreviation, a weather report usually consisting of the 1-2 day
  354. Xforecast, the extended forecast, any special weather advisories, and
  355. Xclimatic data is presented.  Some of the above sections may not be
  356. Xavailable for a given weather site. The options can be used to select
  357. Xsubsets of the presented data.
  358. X.IP
  359. X.B \-u
  360. XThis option eliminates the climate data from the report.
  361. X.IP
  362. X.B \-f
  363. XRestricts the output to the 1-2 day forcast.
  364. X.IP
  365. X.B \-c
  366. XProvide only the climatic data.
  367. X.IP
  368. X.B \-e
  369. XProvide only the extended forcast data.
  370. X.IP
  371. X.B \-s
  372. XProvide only the special advisory reports.
  373. X.IP
  374. X.B \-m
  375. XProvide the marine report if available.
  376. X.IP
  377. X.B \-q
  378. XThis option can only be used with a two letter state abbreviation, and
  379. Xit produces a list of all of the three letter site codes for the
  380. Xstate.
  381. X.PP
  382. XThe entire program is written in perl.
  383. X.SH ENVIRONMENT
  384. XNo environment variables are used.
  385. X.SH FILES
  386. XNone.
  387. X.SH "SEE ALSO"
  388. Xperl(1).
  389. X
  390. ________This_Is_The_END________
  391. if test `wc -c < weather` -ne 9415; then
  392.     echo 'shar: weather was damaged during transit (should have been 9415 bytes)'
  393. fi
  394. fi        ; : end of overwriting check
  395. exit 0
  396.