Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | #!/bin/sh |
2 | # \ | |
3 | exec 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 | ||
19 | exp_version -exit 5.0 | |
20 | ||
21 | if {$argc>0} {set code $argv} else {set code "WBC"} | |
22 | ||
23 | proc timedout {} { | |
24 | send_user "Weather server timed out. Try again later when weather server is not so busy.\n" | |
25 | exit 1 | |
26 | } | |
27 | ||
28 | set timeout 60 | |
29 | ||
30 | set env(TERM) vt100 ;# actual value doesn't matter, just has to be set | |
31 | ||
32 | spawn telnet rainmaker.wunderground.com 3000 | |
33 | while {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 | } | |
53 | send "C\r" | |
54 | expect timeout timedout "Selection:" | |
55 | send "4\r" | |
56 | expect timeout timedout "Selection:" | |
57 | send "1\r" | |
58 | expect timeout timedout "Selection:" | |
59 | send "1\r" | |
60 | expect timeout timedout "city code:" | |
61 | send "$code\r" | |
62 | expect $code ;# discard this | |
63 | ||
64 | while {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 | ||
76 | send "X\r" | |
77 | expect |