|
|
@ -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) |
|
|
|
}) |