Skip to content

Instantly share code, notes, and snippets.

@johnlpage
Created March 4, 2022 13:04
Show Gist options
  • Save johnlpage/2880a81f90c7cf1e15fbddb16d6565c6 to your computer and use it in GitHub Desktop.
Save johnlpage/2880a81f90c7cf1e15fbddb16d6565c6 to your computer and use it in GitHub Desktop.
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