diff --git a/New_APIs/Carbon Footprint API/Readme.md b/New_APIs/Carbon Footprint API/Readme.md new file mode 100644 index 0000000..b3dbcf1 --- /dev/null +++ b/New_APIs/Carbon Footprint API/Readme.md @@ -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 diff --git a/New_APIs/Carbon Footprint API/index.html b/New_APIs/Carbon Footprint API/index.html new file mode 100644 index 0000000..4c708dd --- /dev/null +++ b/New_APIs/Carbon Footprint API/index.html @@ -0,0 +1,37 @@ + + + + + + + Carbon Footprint Calculator + + +
+

Carbon Footprint Calculator

+
+
+
+

Calculate Your Carbon Footprint

+
+ + +
+
+ + +
+ +
+
+

Your Carbon Footprint

+

--

+
+
+ + + diff --git a/New_APIs/Carbon Footprint API/index.js b/New_APIs/Carbon Footprint API/index.js new file mode 100644 index 0000000..a83503f --- /dev/null +++ b/New_APIs/Carbon Footprint API/index.js @@ -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.'); + }); +} diff --git a/New_APIs/Carbon Footprint API/package-lock.json b/New_APIs/Carbon Footprint API/package-lock.json new file mode 100644 index 0000000..ef69539 --- /dev/null +++ b/New_APIs/Carbon Footprint API/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "carbon-footprint-calculator", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "express": { + "version": "4.17.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", + "integrity": "sha512-G7fYv8zS0D7ftu3gnLsOniwhgLU4k9v+1NEtFPP07/Oa8XJ51FtdUKLqIvsTcZo5ua23NO4s9Hr77BM19DOf1g==" + } + } +} diff --git a/New_APIs/Carbon Footprint API/package.json b/New_APIs/Carbon Footprint API/package.json new file mode 100644 index 0000000..9fecf9c --- /dev/null +++ b/New_APIs/Carbon Footprint API/package.json @@ -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" + } +} diff --git a/New_APIs/Carbon Footprint API/server.js b/New_APIs/Carbon Footprint API/server.js new file mode 100644 index 0000000..74380f6 --- /dev/null +++ b/New_APIs/Carbon Footprint API/server.js @@ -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'); +}); diff --git a/New_APIs/Carbon Footprint API/style.css b/New_APIs/Carbon Footprint API/style.css new file mode 100644 index 0000000..127e476 --- /dev/null +++ b/New_APIs/Carbon Footprint API/style.css @@ -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; +}