949d47af44a068902aa552d0b64fb7f02dcf70e6
[spider.git] / cmd / show / wm7d.pl
1 #
2 # Query the WM7D Database server for a callsign
3 #
4 # Largely based on "sh/qrz" and info in the Net::Telnet documentation
5 #
6 # Copyright (c) 2002 Charlie Carroll K1XX
7 #
8 #
9 #
10 use Net::Telnet;
11
12 # wm7d accepts only single callsign
13 sub handle
14 {
15
16         my ($self, $line) = @_;
17         my $call = $self->call;
18         my @out;
19
20         # send 'e24' if allow in Internet.pm is not set to 1
21         return (1, $self->msg('e24')) unless $Internet::allow;
22         return (1, "SHOW/WM7D <callsign>, e.g. SH/WM7D k1xx") unless $line;
23         my $target = $Internet::wm7d_url || 'www.wm7d.net';
24         my $port = 5000;
25         my $cmdprompt = '/query->.*$/';
26
27         my($info, $t);
28                                     
29         $t = new Net::Telnet;
30         $info =  $t->open(Host    => $target,
31                                           Port    => $port,
32                                           Timeout => 20);
33
34         if (!$info) {
35                 push @out, $self->msg('e18', 'WM7D.net');
36         }
37         else {
38         ## Wait for prompt and respond with callsign.
39         $t->waitfor($cmdprompt);
40                 $t->print($line);
41         ($info) = $t->waitfor($cmdprompt);
42     
43                 # Log the lookup
44                 Log('call', "$call: show/wm7d \U$line");
45                 $t->close;
46                 push @out, split /[\r\n]+/, $info;
47         }
48         return (1, @out);
49 }
50