Closed tlestang closed 1 year ago
Just a comment on the postcode validation... the API only needs the outward code, and not the inward code part of the postcode. The outward part varies in length, but the inward part is (almost) always 3 characters, so if the postcode is more than 4 chars then dropping the last 3 might make it valid (this is just a suggestion, but it could make things too messy because it involves doing some validation locally and not on the API)
Also, it might be nice to have a more informative error message for the invalid location just highlighting the format it should be in.
Yeah, that looks good :rocket:
Just added a small check based on your first suggestion. Not a silver bullet, but should make most cases work (unless typo).
Currently the user-specified
location
(postcode for carbonintensity.org.uk) is validated in a separate functioncheck_clean_arguments.validate_location
However
location
format (or whether or not location data is relevant at all) is specific to the API supplying the carbon forecast. This PR moves location validation logic to the API-specific functions. In the case of carbonintensity.org.uk, this isciuk_parse_response_data
. API specific parsing functions inCI_api_interface
module are responsible for raising anInvalidLocationError
if the suppliedlocation
is deemed invalid.Furthermore -- and this might be specific to carbonintensity.org.uk -- postcode is validated a posteriori based on the response from the API.
A few examples