Simplify parliament API scripts.

Remove much-repeated code, factor behaviour into classes.