diff --git a/dark-sky.js b/dark-sky.js index 2913f23..8c0f08e 100644 --- a/dark-sky.js +++ b/dark-sky.js @@ -52,13 +52,18 @@ const logWeatherJson = (jsonFile, loc) => { const hoursList = ['H'] const tempsList = ['°C'] const precipList = ['%P'] - for (let i = 0; i < 9; i++) { + for (let i = 0; i < 16; i += 2) { const hourInfo = weatherInfo['hourly']['data'][i] const date = new Date(hourInfo['time'] * 1000) hoursList.push(date.getHours()) tempsList.push(Math.floor(hourInfo['apparentTemperature'])) - precipList.push(Math.floor(hourInfo['precipProbability'])) + const precipProbability = Math.floor(hourInfo['precipProbability']) + precipList.push((precipProbability < 20) ? '' : precipProbability) } + const maxTempIndex = tempsList.indexOf(Math.max(...tempsList.slice(1))) + const minTempIndex = tempsList.indexOf(Math.min(...tempsList.slice(1))) + tempsList[maxTempIndex] = `${tempsList[maxTempIndex]}+` + tempsList[minTempIndex] = `${tempsList[minTempIndex]}-` log(table([hoursList, tempsList, precipList], TABLE_CONFIG)); } resolve() @@ -66,10 +71,15 @@ const logWeatherJson = (jsonFile, loc) => { }) } +const formatTimeUnit = unit => { return ((unit < 10) ? '0' : '') + unit } + logTablePromises = [ + logWeatherJson('./toronto.json', 'Toronto'), logWeatherJson('./markham.json', 'Markham'), - logWeatherJson('./toronto.json', 'Toronto')] +] Promise.all(logTablePromises).then(results => { - const now = new Date() - log(`${CREDIT_MSG}\n\nLast updated: ${now.getHours()}:${now.getMinutes()}`) + // const now = new Date() + // const lastUpdatedTime = `${formatTimeUnit(now.getHours())}:${formatTimeUnit(now.getMinutes())}` + // log(`${CREDIT_MSG}\n\nLast updated: ${lastUpdatedTime}`) + log(CREDIT_MSG) }) diff --git a/dark-sky.service b/dark-sky.service index f2f4bcf..dee4bf9 100644 --- a/dark-sky.service +++ b/dark-sky.service @@ -3,7 +3,7 @@ Description=Fetch local weather [Service] Type=oneshot -ExecStart=/home/kevin/weather/dark-sky.fish +ExecStart=/home/kevin/weather/dark-sky.sh User=kevin Group=kevin Environment=PATH=/usr/bin:/usr/local/bin diff --git a/dark-sky.timer b/dark-sky.timer index 1b99f93..aa46787 100644 --- a/dark-sky.timer +++ b/dark-sky.timer @@ -2,7 +2,8 @@ Description=Fetch local weather [Timer] -OnCalendar=6,12,18,00:00 +# OnCalendar=6,12,18,00:00 +OnCalendar=*:0 Persistent=true [Install]