elex.api.Election¶
-
class
elex.api.
Election
(**kwargs)¶ Canonical representation of an election on a single date.
-
ballot_measures
¶ Return list of ballot measure objects with results.
-
candidate_reporting_units
¶ Return list of candidate reporting unit objects.
-
candidates
¶ Return list of candidate objects with results.
-
get
(path, **params)¶ Farms out request to api_request. Could possibly handle choosing which parser backend to use – API-only right now. Also the entry point for recording, which is set via environment variable.
Parameters: - path – API url path.
- **params –
A dict of optional parameters to be included in API request.
-
get_race_objects
(parsed_json)¶ Get parsed race objects.
Parameters: parsed_json – Dict of parsed JSON.
-
get_raw_races
(**params)¶ Convenience method for fetching races by election date. Accepts an AP formatting date string, e.g., YYYY-MM-DD. Accepts any number of URL params as kwargs.
If datafile passed to constructor, the file will be used instead of making an HTTP request.
Parameters: **params – A dict of additional parameters to pass to API. Ignored if datafile was passed to the constructor.
-
get_uniques
(candidate_reporting_units)¶ Parses out unique candidates and ballot measures from a list of CandidateReportingUnit objects.
-
get_units
(race_objs)¶ Parses out races, reporting_units, and candidate_reporting_units in a single loop over the race objects.
Parameters: race_objs – A list of top-level Race objects.
-
races
¶ Return list of race objects.
-
reporting_units
¶ Return list of reporting unit objects.
-
results
¶ Return list of candidate reporting unit objects with results.
-
serialize
()¶ Implements
APElection.serialize()
.
-
set_id_field
()¶ Set id to <electiondate>.
-