Command Line Callsign Lookups

I had a need to look up callsign information from the command line, so I wrote some scripts that take callsigns either as arguments or from standard in (stdin) and return the callsign followed by the operator's name. An example:

$ callsign k6rwh
K6RWH, Robert W Harder

The script itself is simple because the hard work is done by Callook.info from Joshua Dick W1JDD, and the only reason the download is more than copying and pasting a few lines is that I wanted to convert the callsigns to titlecase, and that turned out to be more extravagant.

I also use this to take notes during Nets in my favorite (gui) text editor TextMate. I can scribble down callsigns and then process them at once.

Looking up callsigns in TextMate


If you're looking for a vanity callsign, you might also try running through a for loop to see which variations are available:

for N in 0 1 2 3 4 5 6 7 8 9; do callsign K${N}RWH; done
K0RWH,
K1RWH, Richard W Hazzard
K2RWH, Richard W Holst
K3RWH,
K4RWH, Rodney W Humphries
K5RWH, Randall Harwell
K6RWH, Robert W Harder
K7RWH, Richard W Hassler
K8RWH, Roy W Hale
K9RWH,

Download

Download the three files: callsign_titlecase.tgz

The Script

Here's the script. Note that the titlecase command is itself a big, involved script I found somewhere (and is included in the download file above). You can change the last echo command to echo $CS, $NAME if you don't care about titlecasing.

#!/bin/sh
# Command can be called with arguments or to read from stdin
# Author: Robert Harder K6RWH
# With thanks to Joshua Dick W1JDD

# Echoes callsign and name of the operator
function _callsign
{
    local CS=$(echo $1 | tr "[:lower:]" "[:upper:]")
    local NAME=$(curl -s "http://callook.info/index.php?callsign=${CS}&display=text" | grep -A 1 'Name + Address' | grep -v 'Name + Address' | tr -d '\t')
    echo $CS, $(echo $NAME | /usr/bin/env titlecase)
}

# Checks arguments
if [ $# -ge 1 ] # Callsigns passed in as arguments
then
    for cs in $@; do
        _callsign "$cs"
    done
else            # Callsigns read from stdin
    xargs $0
fi
exit 0

Here is an alternate Python version

#!/usr/bin/env python3
# encoding: utf-8
"""
callsign.py

Created by Robert Harder on 2015-10-08.
Copyright (c) 2015 Robert Harder. All rights reserved.
"""

import string

import requests

__author__ = "Robert Harder, K6RWH"


def main():
for arg in sys.argv[1:]:
print_record(arg)


def callsign(cs):
try:
URL = "http://callook.info/index.php"
r = requests.get(URL, params={'callsign': cs, 'display': 'json'})
json = r.json()
return json
except Exception as e:
print("Error", cs, e, file=sys.stderr)
return None


def print_record(cs):
record = callsign(cs)
if record is not None:
if record['status'] == 'INVALID':
print(cs.upper())
else:
name = record['name'].title()
print("{:8s}{}".format(cs.upper(), name))


if __name__ == '__main__':
main()

Explanation

Again, all the hard work is done by Joshua Dick's online service. He imports the FCC database regularly and makes it available as a web service.

The curl command retrieves the station's record in text form, and a series of piped grep calls pulls out the name. Here is what the web service returns without the piping:

$ curl 'http://callook.info/index.php?callsign=K6RWH&display=text'
Type: PERSON
Callsign: K6RWH
Class: TECHNICIAN
Previous Callsign: KJ6CTJ
Name + Address:
ROBERT W HARDER
123 MAIN ST
MONTEREY, CA 93940
Location:
Latitude: 36.57
Longitude: -121.87
Grid Square: CM96b
Other License Information:
Effective: 11/06/2009
Expires: 11/06/2019
Last Action: 11/06/2009
FRN: 0012345678

The first grep filters out the "Name + Address" line plus one following line (the person's name). The second grep filters lines that do not match "Name + Address." Do the math, and you are left with the station's name. Finally a simple translate command removes the leading tab.

ċ
callsign.py
(1k)
Robert Harder,
Oct 9, 2015, 12:41 PM
ċ
callsign_titlecase.tgz
(5k)
Robert Harder,
Feb 9, 2010, 9:39 AM
Comments