Skip to content

Instantly share code, notes, and snippets.

@gpirrotta
Last active December 11, 2021 10:11
Show Gist options
  • Save gpirrotta/f32286d65525f7ab535e6083f94fe860 to your computer and use it in GitHub Desktop.
Save gpirrotta/f32286d65525f7ab535e6083f94fe860 to your computer and use it in GitHub Desktop.
Using Carbon Calculator as python library
from carbon.calculator import CarbonCalculator
from carbon.services import LighthouseService, GreenWebService
# If lighthouse tool is installed globally the following row can be omitted
lighthouse = LighthouseService(lighthouse = PATH_OF_LIGHTHOUSE_TOOL)
# It loads the Green Web Dataset DB (must be a SQL3Lite file)
greenweb = GreenWebService(greenweb = PATH_OF_GREEN_DB)
# It calculates CO2 emissions
carbon = CarbonCalculator(lighthouse=lighthouse, greenweb=greenweb)
carbon.footprint("https://www.unime.it")
print(carbon.co2_grams)
//0.29566587414592505
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment