Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carbon FootPrint API #418

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions New_APIs/Carbon Footprint API/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 🌍 Carbon Footprint API

## Overview

The **Carbon Footprint API** provides data on carbon emissions for various activities, helping users calculate and track their environmental impact. This API is designed to support applications that aim to raise awareness about environmental issues, promote sustainability, and help users reduce their carbon footprint.

## Features

- **Emissions Data**: Access detailed carbon emissions data for a wide range of activities, such as transportation, energy usage, and waste management.
- **Custom Calculations**: Calculate carbon footprints for specific activities based on user input.
- **Tracking & Reporting**: Track and report on users' carbon emissions over time, providing insights into their environmental impact.
- **Data Export**: Export carbon footprint data for further analysis or reporting purposes.

## Getting Started

### Prerequisites

- **API Key**: You will need an API key to access the Carbon Footprint API. You can request an API key by [signing up](#) on our website.

### Installation

To use the Carbon Footprint API, you can install it via npm (if you are building a Node.js application):

```bash
npm install
```
## API Endpoints

### 1. Get Emissions Data

Retrieve carbon emissions data for a specific activity.

**Endpoint**: `/api/v1/emissions`

**Method**: `GET`

**Parameters**:

- `activity`: The type of activity (e.g., `transportation`, `energy`, `waste`).
- `value`: The value associated with the activity (e.g., miles driven, kWh of electricity used).

**Example Request**:

```bash
GET /api/v1/emissions?activity=transportation&value=100
```

## Contributing

We welcome contributions to the Carbon Footprint API! If you'd like to contribute, please follow these steps:

1. Fork the repository.
2. Create a new branch (`git checkout -b feature/your-feature`).
3. Make your changes.
4. Commit your changes (`git commit -am 'Add new feature'`).
5. Push to the branch (`git push origin feature/your-feature`).
6. Create a new Pull Request.


## Contributor
### Sree Vidya
37 changes: 37 additions & 0 deletions New_APIs/Carbon Footprint API/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Carbon Footprint Calculator</title>
</head>
<body>
<header>
<h1>Carbon Footprint Calculator</h1>
</header>
<main>
<div class="input-section">
<h2>Calculate Your Carbon Footprint</h2>
<div class="form-group">
<label for="activityType">Activity Type</label>
<select id="activityType">
<option value="vehicle">Vehicle (km driven)</option>
<option value="flight">Flight (hours)</option>
<option value="energy">Energy (kWh)</option>
</select>
</div>
<div class="form-group">
<label for="activityAmount">Amount</label>
<input type="number" id="activityAmount" placeholder="Enter amount">
</div>
<button id="calculateButton">Calculate</button>
</div>
<div class="result-section">
<h2>Your Carbon Footprint</h2>
<p id="carbonResult">--</p>
</div>
</main>
<script src="index.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions New_APIs/Carbon Footprint API/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
document.getElementById('calculateButton').addEventListener('click', calculateFootprint);

const apiKey = 'YOUR_CARBON_API_KEY'; // Replace with your Carbon Footprint API key

function calculateFootprint() {
const activityType = document.getElementById('activityType').value;
const amount = document.getElementById('activityAmount').value;

if (!amount || amount <= 0) {
alert('Please enter a valid amount.');
return;
}

let apiUrl = '';
let params = {};

switch (activityType) {
case 'vehicle':
apiUrl = 'https://api.carboninterface.com/v1/estimates';
params = {
type: "vehicle",
distance_unit: "km",
distance_value: amount,
vehicle_model_id: "ID_OF_SPECIFIC_VEHICLE_MODEL" // Replace with actual model ID
};
break;
case 'flight':
apiUrl = 'https://api.carboninterface.com/v1/estimates';
params = {
type: "flight",
legs: [
{
departure_airport: "SFO", // Replace with actual airport code
destination_airport: "LAX", // Replace with actual airport code
cabin_class: "economy"
}
],
passengers: amount
};
break;
case 'energy':
apiUrl = 'https://api.carboninterface.com/v1/estimates';
params = {
type: "electricity",
electricity_unit: "kwh",
electricity_value: amount,
country: "us" // Replace with actual country code
};
break;
default:
return;
}

fetch(apiUrl, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(params)
})
.then(response => response.json())
.then(data => {
if (data.data && data.data.attributes && data.data.attributes.carbon_kg) {
document.getElementById('carbonResult').textContent = `${data.data.attributes.carbon_kg} kg CO2`;
} else {
alert('Failed to calculate carbon footprint.');
}
})
.catch(error => {
console.error('Error:', error);
alert('Error calculating carbon footprint.');
});
}
13 changes: 13 additions & 0 deletions New_APIs/Carbon Footprint API/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions New_APIs/Carbon Footprint API/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "carbon-footprint-calculator",
"version": "1.0.0",
"description": "A simple app to calculate carbon footprint using the Carbon Footprint API",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"author": "Your Name",
"license": "ISC",
"dependencies": {
"carbon-footprint-calculator": "file:",
"express": "^4.17.1"
}
}
8 changes: 8 additions & 0 deletions New_APIs/Carbon Footprint API/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require('express');
const app = express();

app.use(express.static('public'));

app.listen(3000, () => {
console.log('Server is running on port 3000');
});
77 changes: 77 additions & 0 deletions New_APIs/Carbon Footprint API/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #2b80d4, #FD746C);
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}

header {
text-align: center;
margin-bottom: 20px;
}

header h1 {
font-size: 3em;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

main {
width: 90%;
max-width: 600px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
padding: 20px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.input-section,
.result-section {
margin-bottom: 20px;
}

.form-group {
margin-bottom: 15px;
}

.form-group label {
display: block;
margin-bottom: 5px;
font-size: 1.2em;
}

input,
select {
width: 100%;
padding: 10px;
font-size: 1em;
border: none;
border-radius: 5px;
outline: none;
}

button {
width: 100%;
padding: 10px;
font-size: 1em;
background-color: #444;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #666;
}

.result-section p {
font-size: 2em;
text-align: center;
margin: 0;
}