Enable extension to other carbon intensity forecast providers #37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It is currently assumed that carbon intensity data comes from carbonintensity.org.uk. While it is likely to remain the case for a time (until we find data sources for other countries, see #22), it didn't seem a lot of effort -- and changes -- to abstract away the API-specific bits, namely:
cats
-- currently a list of tuples.This PR add two new arguments
request_url_fun
andparse_response_fun
to theparsedata.get_tuple
:These two arguments are functions and are specified at runtime.
The list of currently supported API interfaces (i.e. the list of avilable implementations of both functions) is provided by a module
api_interface
. This module makes available a dictionary ofAPIInterface
instances, which are nothing but namedtuple instances specifying both functions for a given web service.Isolating the API-specific logic will also help should the carbonintensity.org.uk change its interface in the future. For instance the endpoint syntax or response structure.