Skip to content

Commit 6f0ed4f

Browse files
authored
Create integration.js
Created
1 parent cbd6832 commit 6f0ed4f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

integration.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Base URL of the Flask API
2+
const API_BASE_URL = "http://127.0.0.1:5000/api";
3+
4+
// Send sustainability goal choice to the backend
5+
async function setSustainabilityGoal(choice) {
6+
try {
7+
const response = await axios.post(`${API_BASE_URL}/sustainability_goal`, { choice });
8+
appendMessage(response.data.message);
9+
} catch (error) {
10+
console.error("Error setting sustainability goal:", error);
11+
}
12+
}
13+
14+
// Upload energy bill and process it
15+
async function uploadEnergyBill(file) {
16+
const reader = new FileReader();
17+
reader.onload = async (e) => {
18+
const fileContent = e.target.result;
19+
try {
20+
const response = await axios.post(`${API_BASE_URL}/energy_bill`, { file_content: fileContent });
21+
appendMessage(JSON.stringify(response.data, null, 2));
22+
} catch (error) {
23+
console.error("Error processing energy bill:", error);
24+
}
25+
};
26+
reader.readAsText(file);
27+
}
28+
29+
// Get recommendations based on analysis
30+
async function getRecommendations(analysis) {
31+
try {
32+
const response = await axios.post(`${API_BASE_URL}/recommendations`, { analysis });
33+
appendMessage(response.data.recommendations);
34+
} catch (error) {
35+
console.error("Error getting recommendations:", error);
36+
}
37+
}
38+
39+
// Fetch vTracker data and display it
40+
async function fetchVTrackerData() {
41+
try {
42+
const response = await axios.get(`${API_BASE_URL}/vtracker_data`);
43+
const data = response.data;
44+
console.log("vTracker Data:", data); // Process and display as needed
45+
} catch (error) {
46+
console.error("Error fetching vTracker data:", error);
47+
}
48+
}
49+
50+
// Example: Bind actions to UI buttons
51+
document.getElementById('fileInput').addEventListener('change', (e) => {
52+
uploadEnergyBill(e.target.files[0]);
53+
});

0 commit comments

Comments
 (0)