Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / bin / weather
CommitLineData
920dae64
AT
1#!/bin/sh
2# \
3exec expect -f "$0" ${1+"$@"}
4
5# weather - Expect script to get the weather (courtesy University of Michigan)
6# Don Libes
7# Version 1.10
8
9# local weather is retrieved if no argument
10# argument is the National Weather Service designation for an area
11# I.e., WBC = Washington DC (oh yeah, that's obvious)
12
13# Notes from Larry Virden <lvirden@yahoo.com> about the new host,
14# rainmaker.wunderground.com: "[the] new site requires the
15# machine doing the request be located in reverse dns lookup
16# or it refuses to provide data." This appears to be a blind error
17# condition on the part of rainmaker.
18
19exp_version -exit 5.0
20
21if {$argc>0} {set code $argv} else {set code "WBC"}
22
23proc timedout {} {
24 send_user "Weather server timed out. Try again later when weather server is not so busy.\n"
25 exit 1
26}
27
28set timeout 60
29
30set env(TERM) vt100 ;# actual value doesn't matter, just has to be set
31
32spawn telnet rainmaker.wunderground.com 3000
33while {1} {
34 expect timeout {
35 send_user "failed to contact weather server\n"
36 exit
37 } "Press Return to continue*" {
38 # this prompt used sometimes, eg, upon opening connection
39 send "\r"
40 } "Press Return for menu*" {
41 # this prompt used sometimes, eg, upon opening connection
42 send "\r"
43 } "M to display main menu*" {
44 # sometimes ask this if there is a weather watch in effect
45 send "M\r"
46 } "Change scrolling to screen*Selection:" {
47 break
48 } eof {
49 send_user "failed to telnet to weather server\n"
50 exit
51 }
52}
53send "C\r"
54expect timeout timedout "Selection:"
55send "4\r"
56expect timeout timedout "Selection:"
57send "1\r"
58expect timeout timedout "Selection:"
59send "1\r"
60expect timeout timedout "city code:"
61send "$code\r"
62expect $code ;# discard this
63
64while {1} {
65 expect timeout {
66 timedout
67 } "Press Return to continue*:*" {
68 send "\r"
69 } "Press Return to display statement, M for menu:*" {
70 send "\r"
71 } -re "(.*)CITY FORECAST MENU.*Selection:" {
72 break
73 }
74}
75
76send "X\r"
77expect