Skip to content

Commit

Permalink
Create weatherData.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Oct 31, 2024
1 parent eaacfac commit 9a27bef
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions blockchain_integration/pi_network/oracles/weatherData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// oracles/weatherData.js

const axios = require("axios");

const API_KEY = "YOUR_WEATHER_API_KEY"; // Replace with your weather API key
const BASE_URL = "https://api.weatherapi.com/v1/current.json"; // Example weather API endpoint

class WeatherData {
constructor() {}

async getCurrentWeather(location) {
try {
const response = await axios.get(`${BASE_URL}?key=${API_KEY}&q=${location}`);
const weatherData = response.data;
return {
location: weatherData.location.name,
temperature: weatherData.current.temp_c,
condition: weatherData.current.condition.text,
humidity: weatherData.current.humidity,
wind: weatherData.current.wind_kph,
};
} catch (error) {
console.error("Error fetching weather data:", error);
throw error;
}
}
}

module.exports = WeatherData;

0 comments on commit 9a27bef

Please sign in to comment.