Wip
This commit is contained in:
22
dark-sky.js
22
dark-sky.js
@@ -11,7 +11,10 @@ const TABLE_CONFIG = {
|
||||
// },
|
||||
border: getBorderCharacters(`ramac`)
|
||||
}
|
||||
const CREDIT_MSG = "Powered by Dark Sky: https://darksky.net/poweredby/"
|
||||
const HIDE_PRECIP_LESS_THAN = 10
|
||||
// const CREDIT_MSG = "Powered by Dark Sky: https://darksky.net/poweredby/"
|
||||
// const CREDIT_MSG = "https://darksky.net/poweredby • https://smol.gq/wthr-src\n"
|
||||
const CREDIT_MSG = "darksky.net/poweredby • smol.gq/wthr-src\n"
|
||||
|
||||
// https://medium.com/@osiolabs/read-write-json-files-with-node-js-92d03cc82824
|
||||
const jsonReader = (filePath, cb) => {
|
||||
@@ -28,6 +31,8 @@ const jsonReader = (filePath, cb) => {
|
||||
})
|
||||
}
|
||||
|
||||
const round5 = x => { return Math.ceil(x / 5) * 5 }
|
||||
|
||||
const logWeatherJson = (jsonFile, loc) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
jsonReader(jsonFile, (err, weatherInfo) => {
|
||||
@@ -57,8 +62,10 @@ const logWeatherJson = (jsonFile, loc) => {
|
||||
const date = new Date(hourInfo['time'] * 1000)
|
||||
hoursList.push(date.getHours())
|
||||
tempsList.push(Math.floor(hourInfo['apparentTemperature']))
|
||||
const precipProbability = Math.floor(hourInfo['precipProbability'])
|
||||
precipList.push((precipProbability < 20) ? '' : precipProbability)
|
||||
// const precipProbability = Math.floor(hourInfo['precipProbability'] * 10) / 10
|
||||
const precipProbability = round5(hourInfo['precipProbability'] * 100)
|
||||
precipList.push((precipProbability < HIDE_PRECIP_LESS_THAN)
|
||||
? '' : precipProbability)
|
||||
}
|
||||
const maxTempIndex = tempsList.indexOf(Math.max(...tempsList.slice(1)))
|
||||
const minTempIndex = tempsList.indexOf(Math.min(...tempsList.slice(1)))
|
||||
@@ -72,14 +79,9 @@ const logWeatherJson = (jsonFile, loc) => {
|
||||
}
|
||||
|
||||
const formatTimeUnit = unit => { return ((unit < 10) ? '0' : '') + unit }
|
||||
|
||||
log(CREDIT_MSG)
|
||||
logTablePromises = [
|
||||
logWeatherJson('./toronto.json', 'Toronto'),
|
||||
logWeatherJson('./markham.json', 'Markham'),
|
||||
]
|
||||
Promise.all(logTablePromises).then(results => {
|
||||
// const now = new Date()
|
||||
// const lastUpdatedTime = `${formatTimeUnit(now.getHours())}:${formatTimeUnit(now.getMinutes())}`
|
||||
// log(`${CREDIT_MSG}\n\nLast updated: ${lastUpdatedTime}`)
|
||||
log(CREDIT_MSG)
|
||||
})
|
||||
Promise.all(logTablePromises).then(results => {})
|
||||
|
||||
Reference in New Issue
Block a user