Factor out common bits

In anticipation of writing a separate parser for the general
election results, factor out the common functionality into
a base module.