@click.command(name="bake.election_file", help="Write election and candidate "
    "data with on election per file")
@election_file_options
def election_file(state, fmt='csv', outputdir=None, datefilter=None,
                  electiontype=None, level=None, raw=False):
    timestamp = datetime.now()

    if raw:
        baker_cls = RawBaker
    else:
        baker_cls = Baker

    if datefilter is None or re.match( r'\d{4}', datefilter):
        # No date specfied, so bake all elections or date filter
        # represents a single year, so bake all elections for that year.
        elections = get_election_dates_types(state, datefilter)
    else:
        # Date filter is for a day, grab that election specifically
        if electiontype is None:
            msg = "You must specify the election type when baking results for a single date."
            sys.exit(msg)
        elections = [(datefilter, electiontype)]

    for election_date, election_type in elections:
        if level is not None:
            reporting_levels = [level]
        else:
            reporting_levels = reporting_levels_for_election(state, election_date,
                election_type, raw)

        for reporting_level in reporting_levels:
            msg = "Baking {} level results for {} election on {}\n".format(
                reporting_level, election_type, election_date)
            sys.stdout.write(msg)
            baker = baker_cls(state=state, datefilter=election_date,
                  election_type=election_type, reporting_level=reporting_level)

            baker.collect_items()\
                 .write(fmt, outputdir=outputdir, timestamp=timestamp) \
                 .write_manifest(outputdir=outputdir, timestamp=timestamp)
Write election and candidate data with one election per file.
dataset/ETHPy150Open openelections/openelections-core/openelex/tasks/bake.py/election_file