elex.api.utils¶
Utility functions to record raw election results and handle low-level HTTP interaction with the Associated Press Election API.
-
class
elex.api.utils.
UnicodeMixin
¶ Python 2 + 3 compatibility for __unicode__
-
elex.api.utils.
api_request
(path, **params)¶ Function wrapping Python-requests for making a request to the AP’s elections API.
A properly formatted request: * Modifies the BASE_URL with a path. * Contains an API_KEY. * Returns a response object.
Parameters: **params – Extra parameters to pass to requests. For example, apiKey=”<YOUR API KEY>, your AP API key, or national=True, for national-only results.
-
elex.api.utils.
write_recording
(payload)¶ Record a timestamped version of an Associated Press Elections API data download.
Presumes JSON at the moment. Would have to refactor if using XML or FTP. FACTOR FOR USE; REFACTOR FOR REUSE.
Parameters: payload – JSON payload from Associated Press Elections API.