Skip to content

Commit

Permalink
Hi dad
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywonchung committed Oct 5, 2024
1 parent 1f901c6 commit cee2bd2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions zeus/carbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,24 @@ def get_current_carbon_intensity(self) -> float:
!!! Note
In some locations, there is no recent carbon intensity data. `self.estimate` can be used to approximate the carbon intensity in such cases.
"""
resp_str = None
try:
url = (
f"https://api.electricitymap.org/v3/carbon-intensity/latest?lat={self.lat}&lon={self.long}"
+ f"&disableEstimations={not self.estimate}&emissionFactorType={self.emission_factor_type}"
)
resp = requests.get(url)
resp_str = resp.text
except requests.exceptions.RequestException as e:
logger.exception(
"Failed to retrieve recent carbon intensnity measurement: %s", e
)
raise

try:
return resp.json()["carbonIntensity"]
except KeyError as e:
# Raise exception when carbonIntensity does not exist in response
raise ZeusCarbonIntensityNotFoundError(
f"Recent carbon intensity measurement not found at `({self.lat}, {self.long})` "
f"with estimate set to `{self.estimate}` and emission_factor_type set to `{self.emission_factor_type}`\n"
f"JSON Response: {resp_str}"
f"JSON Response: {resp.text}"
) from e
except requests.exceptions.RequestException as e:
logger.exception(
"Failed to retrieve recent carbon intensnity measurement: %s", e
)
raise

0 comments on commit cee2bd2

Please sign in to comment.