Created
March 4, 2022 13:04
-
-
Save johnlpage/2880a81f90c7cf1e15fbddb16d6565c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports = async function(arg) { | |
const axios = require('axios'); | |
const APIKEY = "XXXXXXXXXXXXXXXXXXXf"; | |
const endpoint = `https://api.openweathermap.org/data/2.5/weather?lat=55.7384&lon=-4.216&appid=${APIKEY}`; | |
try { | |
weather = await axios.get(endpoint); | |
if (weather.status == 200) { | |
console.log(JSON.stringify(weather.data)); | |
const roomtemps = context.services.get("mongodb-atlas").db("energy").collection("roomtemps"); | |
// add this to the roomtemps too for simplicity | |
let temp_c = Math.floor(weather.data.main.temp - 273); | |
await roomtemps.insertOne({ | |
location: "Outside", | |
date: new Date(), | |
temp: temp_c | |
}); | |
} | |
} catch (e) { | |
console.error(e); | |
} | |
return { | |
arg: arg | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment