@click.command(name="bake.results_status_json", help="Output a JSON file "
    "describing available results for each election")
@click.option('--state', help="Two-letter state-abbreviation, e.g. NY")
@click.option('--bakeall', is_flag=True, help='Bake metadata for all states '
              'instead of the specified state')
@click.option('--outputdir', help='Create JSON files in this directory. '
              'If baking a single file. output is sent to stdout.')
def results_status_json(state=None, bakeall=False, outputdir=None):
    filename_tpl = "elections-{}.json"

    if state:
        # Bake metadata for a single state to stdout
        print json.dumps(statuses_for_state(state))
        sys.exit(0)

    if not (bakeall and outputdir):
        # Bad arguments.  Output a message and exit. 
        msg = ("You must specify a state or the --bakeall flag and an "
               "output directory")
        sys.exit(msg)
     
    # The use has specified the bakeall flag and an outputdir.  Bake files for
    # all states.
    for state in STATE_POSTALS:
        statuses = statuses_for_state(state)
        output_path = os.path.join(outputdir,
            filename_tpl.format(state.lower()))
        with open(output_path, 'w') as f:
            json.dump(statuses, f)
Output a JSON file describing available results for each election.
dataset/ETHPy150Open openelections/openelections-core/openelex/tasks/bake.py/results_status_json