#!/usr/bin/perl ####################################################################### # This looks up callsigns on the QTH 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/qth.txt # # # # This requires a QTH registered account to work Edit your # # username and password below # # # # # # Version: 1.0 Date:10/31/2011 # # # ####################################################################### # Uncomment to do the dumper printout below if needed use Data::Dumper; use IO::Handle; 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 QTH USERNAME HERE"; my $password="PUT YOUR QTH 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 autoflush STDOUT; die "\nYou must edit $0 and set up your QTH username and password\nThis requires a QTH registered account to work\nGo to: http://www.hamqth.com/\n\n" if $username eq 'PUT YOUR QTH USERNAME HERE'; # Get a session ID to authenticate you to QTH print " This is a call sign lookup that works against QTH.com\n"; print " Enter a call at the prompt or type 'q' to quit\n"; my $sessionget = get "http://www.hamqth.com/xml.php?u=$username&p=$password"; #print Dumper($sessionget); $sessionget =~ s{encoding="iso8859-1"}{encoding="utf-8"}; my $info = XMLin($sessionget); #print Dumper( $info ); # Handle any errors on the initial connection to QTH and print them out die "Something isn't right connecting to QTH...the error was: $info->{session}->{error}\n" if defined $info->{session}->{error}; my $seskey = $info->{session}->{session_id}; #print Dumper( $seskey ); while ($seskey) { print " Callsign? or q: "; chomp (my $call = ); $call =~ s/ //; # Should we quit? if ( $call =~ m/^q.*/ ) { exit; } # Not exactly thorough but stops some typos 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://www.hamqth.com/xml.php?id=$seskey&callsign=$call&prg=kc2rgw-looker-upper"; $getlookup =~ s{encoding="iso8859-1"}{encoding="utf-8"}; my $lookup = XMLin($getlookup); # If we get a Not Found or some other error, say so here if (defined $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. Change the print # statements below to suit what you want for format output. # print Dumper( $lookup ); print "\n CALL: $lookup->{search}->{callsign}\tLICDATE: $lookup->{search}->{lic_year}\tCOUNTRY: $lookup->{search}->{country}\n"; print " NICKNAME:$lookup->{search}->{nick}\tFULL-NAME:$lookup->{search}->{adr_name} \n"; print " QTH: $lookup->{search}->{qth}\n"; print " ADDRESS:\n"; if (defined $lookup->{search}->{adr_street1}) { print " $lookup->{search}->{adr_street1}\n"; } if (defined $lookup->{search}->{adr_street2}) { print " $lookup->{search}->{adr_street2}\n"; } if (defined $lookup->{search}->{adr_street3}) { print " $lookup->{search}->{adr_street3}\n"; } print " $lookup->{search}->{adr_city}, $lookup->{search}->{us_state} $lookup->{search}->{adr_zip} \n"; print " COUNTRY:$lookup->{search}->{adr_country} \n"; if (defined $lookup->{search}->{district}) { print " DISTRICT: $lookup->{search}->{district}"; } if (defined $lookup->{search}->{us_county}) { print " COUNTY: $lookup->{search}->{us_county}"; } print " LOC:$lookup->{search}->{grid} CQ:$lookup->{search}->{CQ} ITU:$lookup->{search}->{itu}\n"; print " QSL: $lookup->{search}->{qsl} QSL-VIA: $lookup->{search}->{qsl_via}\n"; print " LOTW: $lookup->{search}->{lotw} eQSL: $lookup->{search}->{eqsl} \n"; if (defined $lookup->{search}->{web}) { print " WWW: $lookup->{search}->{web}\n"; } if (defined $lookup->{search}->{email}) { print " EMAIL: $lookup->{search}->{email}"; } if (defined $lookup->{search}->{skype}) { print " SKYPE: $lookup->{search}->{skype}\n"; } print " FULL RECORD: http://www.hamqth.com/$call\n\n"; }