#!/usr/bin/perl ####################################################################### # This looks up callsigns on the QRZ web service and parses the # # output for the basics of a lookup. # # # # Written by Kingsqueak KC2RGW #hamradio irc.openprojects.net # # # # Distributed here: http://www.kingsqueak.org/stuff/qrz.txt # # # # This requires a QRZ subscription account to work Edit your # # username and password below # # # # Thanks to Botje #perl on freenode for pointing out a really # # simple fix to a major annoyance for line buffering in inetd # # # # Version: 2.7 Date:1/31/2010 # # # ####################################################################### #use strict; # warnings disabled to avoid noise for null fields when lookup info # is missing something like county #use warnings; # Uncomment to do the dumper printout below if needed #use Data::Dumper; use XML::Simple; use LWP::Simple qw(get); # Set your QRZ username and password here...you must be registered or this # will not work! my $username="PUT YOUR QRZ USERNAME HERE"; my $password="PUT YOUR QRZ PASSWORD HERE"; # This is needed particularly if you run via inetd and this is actually # a component app for a packet node. Should work with this in a # terminal anyway STDOUT->autoflush; die "\nYou must edit $0 and set up your QRZ username and password\nThis requires a QRZ subscription account to work\n\n" if $username eq 'PUT YOUR QRZ USERNAME HERE'; # Get a session ID to authenticate you to QRZ print " This is a call sign lookup that works against QRZ.com\n"; print " Enter a call at the prompt or type 'q' to quit\n"; my $sessionget = get "http://xml.qrz.com/xml?&username=$username&password=$password"; $sessionget =~ s{encoding="iso8859-1"}{encoding="utf-8"}; my $info = XMLin($sessionget); # Handle any errors on the initial connection to QRZ and print them out die "Something isn't right connecting to QRZ...the error was: $info->{Session}->{Error}\n" if defined $info->{Session}->{Error}; my $seskey = "$info->{Session}->{Key}"; while ($seskey) { # $SIG{INT} = "nope" ; # sub nope {}; print " Callsign? or q: "; chomp( my $call = ); #$call =~ s/\r$//; # Should we quit? if ( $call =~ m/^q.*/ ) { exit; } if ( not $call =~ m/^[a-zA-Z].*[0-9][a-zA-Z].*$/) { print "You entered an invalid call, try again. \n"; next; } # Now we have a key, we can do the lookup of the call my $getlookup = get "http://xml.qrz.com/xml?s=$seskey;callsign=$call"; $getlookup =~ s{encoding="iso8859-1"}{encoding="utf-8"}; my $lookup = XMLin($getlookup); # Now we can get the bio information too my $getbio = get "http://xml.qrz.com/xml?s=$seskey;bio=$call"; $getbio =~ s{encoding="iso8859-1"}{encoding="utf-8"}; my $bio = XMLin($getbio); # If we get a Not Found or some other error, say so here if ($lookup->{Session}->{Error}) { print "\nNo record returned for $call reason: $lookup->{Session}->{Error}\n\n"; next; } # If you uncomment the following print Dumper statements you can see # all the fields that are returned in raw format. The spec is here # http://online.qrz.com/specifications.html for available fields. # print Dumper($lookup); # print Dumper($bio); print " $lookup->{Session}->{GMTime} GMT\n"; print " $lookup->{Callsign}->{call}\tlookups: $lookup->{Callsign}->{u_views}\n"; print " class: $lookup->{Callsign}->{class}\texpires: $lookup->{Callsign}->{expdate} \n"; print " $lookup->{Callsign}->{name}, $lookup->{Callsign}->{fname} \n"; print " $lookup->{Callsign}->{addr1} \n"; print " $lookup->{Callsign}->{addr2}, $lookup->{Callsign}->{state} $lookup->{Callsign}->{zip} \n"; print " $lookup->{Callsign}->{county} $lookup->{Callsign}->{grid} $lookup->{Callsign}->{country} \n"; print " qslmgr: $lookup->{Callsign}->{qslmgr}\n"; print " email: $lookup->{Callsign}->{email} \n"; print " ==========================================================================\n"; print " Biography Info Link URL\n"; print " ==========================================================================\n"; print " $lookup->{Callsign}->{bio}\n"; print " $bio->{Bio}->{bio} \n\n\n"; }