require('dotenv').config(); const axios = require('axios'); const params = ['STATION', 'KEY', 'ORG', 'BUCKET', 'SERVER']; params.forEach(p => { if (!process.env[`FEATHER_${p}`]) { console.log(`MISSING FEATHER_${p}`); process.exit(2); } }); let config = { method: 'get', maxBodyLength: Infinity, url: `https://api.weather.gov/stations/${process.env.FEATHER_STATION}/observations/latest`, headers: { 'User-Agent': '(lgbt.cray.app.feather, liz@hacdc.org)' } }; axios.request(config) .then((response) => { // console.log(JSON.stringify(response.data)); let data = response.data.properties; const metrics = ['temperature', 'dewpoint', 'windDirection', 'windSpeed', 'windGust', 'barometricPressure', 'seaLevelPressure', 'visibility', 'precipitationLast3Hours', 'relativeHumidity', 'windChill']; let payload = `${process.env.FEATHER_STATION} `; metrics.forEach(metric => { let value = data[metric].value; if (value === 'null' || value === null){ value = -1; } payload += `${metric}=${value},` }); payload = payload.slice(0, -1); axios.post(`${process.env.FEATHER_SERVER}/api/v2/write?orgID=${process.env.FEATHER_ORG}&bucket=${process.env.FEATHER_BUCKET}`, payload, { headers: { Authorization: `Token ${process.env.FEATHER_KEY}`, 'Content-Type': 'text/plain' } } ) }) .catch((error) => { console.log(error); });