added callsign to logging
[spider.git] / cmd / show / qrz.pl
1 #
2 # Query the QRZ Database server for a callsign
3 #
4 # from an idea by Steve Franke K9AN and information from Angel EA7WA
5 #
6 # $Id$
7 #
8 my ($self, $line) = @_;
9 my @list = split /\s+/, $line;                # generate a list of callsigns
10 my $l;
11 my $call = $self->call;
12 my @out;
13
14 return (1, "SHOW/QRZ <callsign>, e.g. SH/QRZ g1tlh") unless @list;
15
16 use Net::Telnet;
17
18 my $t = new Net::Telnet;
19
20 push @out, $self->msg('call1', "QRZ.com");
21 foreach $l (@list) {
22         $t->open(Host     =>  "qrz.com",
23                          Port     =>  80,
24                          Timeout  =>  5);
25         if ($t) {
26                 $t->print("GET /database?callsign=$l HTTP/1.0\n\n");
27                 Log('call', "$call: show/qrz $l");
28                 my $state = "call";
29                 while (my $result = $t->getline) {
30 #                       print "$state: $result";
31                         if ($state eq 'call' && $result =~ /$l/i) {
32                                 $state = 'getaddr';
33                                 push @out, uc $l;
34                         } elsif ($state eq 'getaddr' || $state eq 'inaddr') {
35                                 if ($result =~ /^\s+([\w\s.,;:-]+)(?:<br>)?$/) {
36                                         my $line = $1;
37                                         unless ($line =~ /^\s+$/) {
38                                                 push @out, $line;
39                                                 $state = 'inaddr' unless $state eq 'inaddr';
40                                         }
41                                 } else {
42                                         $state = 'runout' if $state eq 'inaddr';
43                                 }
44                         }
45                 }
46                 $t->close;
47         } else {
48                 push @out, $self->msg('e18', 'QRZ.com');
49         }
50 }
51
52 return (1, @out);