addbooktool Validator and Exporter

By: Owen T. Heisler
Published: 2015-03-02

I wrote a syntax specification and the following Python application for validating data in an external contact information database and exporting to various formats. The application has a command line interface and a graphical interface, both interfaces cover the same functionality.

Excerpt from the README

This utility reads an Addbook (AB4D) database and provides the following functionality:

  • Validates the Names table against syntax.md

  • Provides a list of names lacking directions/coordinates

  • Exports contacts to CSV, vCard, and gpsbabel formats

Input is an Addbook (AB4D) database file.

Example command, using gpsbabel for one of its supported output formats, is something like this:

$ python3 addbooktool export Addbook.AB4D | \
  gpsbabel -i unicsv -f - -o garmin_gpi,category="Addbook" -F
  gpsbabel_out.gpi

Usage

$ addbooktool -h
usage: [-h] [-p PASSWORD] [-V] {validate,export} ... input

This is a utility for working with Addbook data.

positional arguments:
  {validate,export}
    validate            validate fields in names table
    export              export contacts
  input                 Source AB4D file

optional arguments:
  -h, --help            show this help message and exit
  -p PASSWORD, --password PASSWORD
                        provide password for AB4D database file (only
                        required on Windows)
  -V, --version         show program's version number and exit

For subcommand usage information, run eg. 'addbooktool validate -h'.
$ addbooktool validate -h
usage:  validate [-h] [-d] [-c] [-a]

The validate command returns a list of the records which have invalid
syntax. Use the optional arguments to relax or restrict the
validation.

optional arguments:
  -h, --help         show this help message and exit
  -d, --directions   require entries to include directions
  -c, --coordinates  require entries to include coordinates
  -a, --full-addr    require entries to have full addresses (rather
                     than just city/state)
$ addbooktool export -h
usage:  export [-h] [-f {gcsv,gpi,gpx,vcard_dir,vcard_file}]
               [-o OUTPUT]

The export command returns the records in the specified format.

optional arguments:
  -h, --help            show this help message and exit
  -f {gcsv,gpi,gpx,vcard_dir,vcard_file}, --format {gcsv,gpi,gpx,vcard_dir,vcard_file}
                        output format, one of: GPSBabel unicsv, GPI,
                        GPX, vCard folder, vCard file
  -o OUTPUT, --output OUTPUT
                        output file or directory, depending on
                        selected format (The default output location
                        for single-file formats is stdout, including
                        for binary formats. The default output
                        location for multiple-file formats is the
                        current directory. If the selected directory
                        is not empty, a temporary directory will be
                        created.)