5 Commits

Author SHA1 Message Date
b0c5b7ff48 Wip 2019-10-01 16:17:18 -04:00
c2f187cfdf Notate high/low, hide low precip %
Only show every other hour horizontally.
2019-09-30 07:36:16 -04:00
26ccdacf66 Convert fish script to Bash 2019-09-29 21:50:20 -04:00
3ad87f085e Markham/Toronto tables, horizontal orientation
Credit Dark Sky.
2019-09-29 14:41:30 -04:00
831dce0656 Update service/timer, ASCII border 2019-09-29 03:28:09 -04:00
14 changed files with 265 additions and 1237 deletions

6
.gitignore vendored
View File

@@ -1,9 +1,7 @@
*.csv
*.html
*.txt *.txt
api-keys-fish.sh api-keys*.sh
dark-sky.json *.json
# node {{{ - # node {{{ -

3
.gitmodules vendored
View File

@@ -1,3 +0,0 @@
[submodule "csi.js"]
path = csi.js
url = https://github.com/LexmarkWeb/csi.js

1
csi.js

Submodule csi.js deleted from 2d99a233a5

View File

@@ -1,14 +0,0 @@
#!/bin/bash
echo "<table>" ;
print_header=true
while read INPUT ; do
if $print_header;then
# echo "<tr><th>$INPUT" | sed -e 's/:[^,]*\(,\|$\)/<\/th><th>/g'
echo "<tr><th>${INPUT//,/</th><th>}</th></tr>" ;
print_header=false
else
echo "<tr><td>${INPUT//,/</td><td>}</td></tr>" ;
fi
done < dark-sky.csv ;
echo "</table>"

View File

@@ -1,7 +0,0 @@
source api-keys-fish.sh
# IBM
set curl_url "https://api.darksky.net/forecast/$DARK_SKY_KEY/43.8180904,-79.3350555?exclude=minutely%2Cdaily%2Calerts%2Cflags&units=auto"
curl --request GET --url $curl_url > dark-sky.json
node dark-sky.js > dark-sky.csv
./csv-to-html.sh > dark-sky.html

View File

@@ -1,8 +1,20 @@
const log = console.log const log = console.log
const fs = require('fs') const fs = require('fs')
const {table} = require('table') const {table, getBorderCharacters} = require('table')
const argv = require('yargs').argv
const HOURS_AHEAD = 12 const TABLE_CONFIG = {
// columns: {
// 0: { alignment: 'center' },
// 1: { alignment: 'center' },
// 2: { alignment: 'center' },
// },
border: getBorderCharacters(`ramac`)
}
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 // https://medium.com/@osiolabs/read-write-json-files-with-node-js-92d03cc82824
const jsonReader = (filePath, cb) => { const jsonReader = (filePath, cb) => {
@@ -19,28 +31,57 @@ const jsonReader = (filePath, cb) => {
}) })
} }
jsonReader('./dark-sky.json', (err, weatherInfo) => { const round5 = x => { return Math.ceil(x / 5) * 5 }
if (err) {
console.log(err)
return
}
const tableConfig = {
columns: {
0: { alignment: 'center' },
1: { alignment: 'center' },
2: { alignment: 'center' },
}
}
const infoList = [['H', '°C', '%P']]
for (let i = 0; i < HOURS_AHEAD; i++) {
const hourInfo = weatherInfo['hourly']['data'][i]
const date = new Date(hourInfo['time'] * 1000)
infoList.push([date.getHours(),
Math.floor(hourInfo['apparentTemperature']),
Math.floor(hourInfo['precipProbability'])])
}
// log(table(infoList, tableConfig)); const logWeatherJson = (jsonFile, loc) => {
log(infoList.map(row => { return row.join() }).join('\n')) return new Promise((resolve, reject) => {
}) jsonReader(jsonFile, (err, weatherInfo) => {
if (err) {
reject(err)
}
log(loc)
if (argv.v) {
const infoList = [['H', '°C', '%P']]
for (let i = 0; i < 12; i++) {
const hourInfo = weatherInfo['hourly']['data'][i]
const date = new Date(hourInfo['time'] * 1000)
infoList.push([date.getHours(),
Math.floor(hourInfo['apparentTemperature']),
Math.floor(hourInfo['precipProbability'])])
}
log(table(infoList, TABLE_CONFIG));
} else {
// horizontal
const hoursList = ['H']
const tempsList = ['°C']
const precipList = ['%P']
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']))
// 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)))
tempsList[maxTempIndex] = `${tempsList[maxTempIndex]}+`
tempsList[minTempIndex] = `${tempsList[minTempIndex]}-`
log(table([hoursList, tempsList, precipList], TABLE_CONFIG));
}
resolve()
})
})
}
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 => {})

14
dark-sky.service Normal file
View File

@@ -0,0 +1,14 @@
[Unit]
Description=Fetch local weather
[Service]
Type=oneshot
ExecStart=/home/kevin/weather/dark-sky.sh
User=kevin
Group=kevin
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/home/kevin/weather
[Install]
WantedBy=multi-user.target

16
dark-sky.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/bash
source api-keys.sh
# takes (coords, location_name) as parameters
update-weather-json() {
curl_url="https://api.darksky.net/forecast/$DARK_SKY_KEY/$1?exclude=minutely%2Cdaily%2Calerts%2Cflags&units=auto"
curl --request GET --url $curl_url > $2.json
# echo "curl --request GET --url $curl_url > $2.json"
}
update-weather-json "43.8180904,-79.3350555" "markham"
update-weather-json "43.6596426,-79.3976676" "toronto"
node dark-sky.js > dark-sky.txt
# node dark-sky.js

10
dark-sky.timer Normal file
View File

@@ -0,0 +1,10 @@
[Unit]
Description=Fetch local weather
[Timer]
# OnCalendar=6,12,18,00:00
OnCalendar=*:0
Persistent=true
[Install]
WantedBy=timers.target

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +0,0 @@
<html>
<head>
<script src="csi.js/csi.min.js"></script>
<!-- <script src="http://livejs.com/live.js" charset="utf-8"></script> -->
<link rel="stylesheet" href="github-pandoc.css">
</head>
<body>
<div data-include="dark-sky.html"></div>
</body>
</html>

130
package-lock.json generated
View File

@@ -33,6 +33,21 @@
"resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz",
"integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==" "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg=="
}, },
"camelcase": {
"version": "5.3.1",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg=="
},
"cliui": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz",
"integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==",
"requires": {
"string-width": "^3.1.0",
"strip-ansi": "^5.2.0",
"wrap-ansi": "^5.1.0"
}
},
"color-convert": { "color-convert": {
"version": "1.9.3", "version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
@@ -46,6 +61,11 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
}, },
"decamelize": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
"integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA="
},
"emoji-regex": { "emoji-regex": {
"version": "7.0.3", "version": "7.0.3",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz",
@@ -61,6 +81,19 @@
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I="
}, },
"find-up": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz",
"integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==",
"requires": {
"locate-path": "^3.0.0"
}
},
"get-caller-file": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="
},
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
@@ -71,16 +104,66 @@
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
}, },
"locate-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz",
"integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==",
"requires": {
"p-locate": "^3.0.0",
"path-exists": "^3.0.0"
}
},
"lodash": { "lodash": {
"version": "4.17.15", "version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
}, },
"p-limit": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.1.tgz",
"integrity": "sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg==",
"requires": {
"p-try": "^2.0.0"
}
},
"p-locate": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz",
"integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==",
"requires": {
"p-limit": "^2.0.0"
}
},
"p-try": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ=="
},
"path-exists": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
"integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU="
},
"punycode": { "punycode": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
}, },
"require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
"integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I="
},
"require-main-filename": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz",
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg=="
},
"set-blocking": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc="
},
"slice-ansi": { "slice-ansi": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz",
@@ -127,6 +210,53 @@
"requires": { "requires": {
"punycode": "^2.1.0" "punycode": "^2.1.0"
} }
},
"which-module": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz",
"integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho="
},
"wrap-ansi": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz",
"integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==",
"requires": {
"ansi-styles": "^3.2.0",
"string-width": "^3.0.0",
"strip-ansi": "^5.0.0"
}
},
"y18n": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",
"integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w=="
},
"yargs": {
"version": "14.0.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-14.0.0.tgz",
"integrity": "sha512-ssa5JuRjMeZEUjg7bEL99AwpitxU/zWGAGpdj0di41pOEmJti8NR6kyUIJBkR78DTYNPZOU08luUo0GTHuB+ow==",
"requires": {
"cliui": "^5.0.0",
"decamelize": "^1.2.0",
"find-up": "^3.0.0",
"get-caller-file": "^2.0.1",
"require-directory": "^2.1.1",
"require-main-filename": "^2.0.0",
"set-blocking": "^2.0.0",
"string-width": "^3.0.0",
"which-module": "^2.0.0",
"y18n": "^4.0.0",
"yargs-parser": "^13.1.1"
}
},
"yargs-parser": {
"version": "13.1.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz",
"integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==",
"requires": {
"camelcase": "^5.0.0",
"decamelize": "^1.2.0"
}
} }
} }
} }

View File

@@ -9,6 +9,7 @@
"author": "Kevin Mok", "author": "Kevin Mok",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"table": "^5.4.6" "table": "^5.4.6",
"yargs": "^14.0.0"
} }
} }

24
todo.md Normal file
View File

@@ -0,0 +1,24 @@
# Todo
- deliver text/HTML depending on User-Agent in header
- https://nginx.org/en/docs/http/ngx_http_browser_module.html
- https://www.nginx.com/resources/wiki/modules/user_agent/
- https://www.whatsmyua.info/api/v1/ua
- colors
- ANSI escape codes
- https://github.com/gabx/archlinux/blob/master/etc/scripts/colortest
- icons
# Done
- display both locations
- location text
- table orientation
- credit Dark Sky
- "Powered by Dark Sky: https://darksky.net/poweredby/"
- Dark Sky image
- https://darksky.net/dev/docs/terms
# Archived
- fetch on load
- Lua os.execute in Nginx
- fetch JSON in JS
- generate table dynamically