Chris Adams / Mar 03 2023
carbon.txt demo
First of all, install requests so we can easily make http requests with python
!pip install requests3.7s
import requestspayload = { "url": "https://fershad.com/carbon.txt"}response = requests.post("https://staging-admin.greenweb.org/api/v3/carbontxt", data=payload)0.9s
import jsonjson_content = response.json()with open("/results/response-as-pretty.json", "w") as jsonfile: jsonfile.write(json.dumps(json_content))0.0s
We can also test out passing our own carbon.txt content, to save needing to update a page again and again:
edited_carbon_txt = """[upstream]providers = [ # overwriting this to get a non cloudflare response 'branch.climateaction.tech'][org]credentials = [ # These are evidence of things I do to account for the carbon emissions of this website. { domain = "fershad.com", doctype = "webpage", url = "https://fershad.com/for-good/"}]"""payload = { "url": "https://fershad.com/carbon.txt", "carbon_txt": edited_carbon_txt}new_response = requests.post("https://staging-admin.greenweb.org/api/v3/carbontxt", data=payload)new_response0.2s
with open("/results/new-response-as-pretty.json", "w") as jsonfile: jsonfile.write(new_response.content.decode('utf-8'))0.0s