This commit is contained in:
Connor 2017-07-30 19:41:51 -07:00 committed by GitHub
parent 075418af21
commit 0243eb33dd

View File

@ -8,14 +8,12 @@ set -e
# editing this script.
# downloading a python script.
# python 2 or 3.
# a web browser
# curl
# GNU sort
# GNU awk
# a web browser.
# curl.
# GNU sort.
# GNU awk.
# KNOWN ISSUES:
# stops printing at the first = character per field.
# this should be an easy fix but i'm lazy.
# output is not always sorted by viewer count.
# TODO:
@ -46,19 +44,23 @@ client_id="client-id: [fill me in!]"
json2() {
# download this from https://github.com/vi/json2/blob/master/json2
# and edit this line accordingly.
python ~/src/json2/json2 "$@"
~/python3 ~/src/json2/json2 "$@"
}
curl -LsS 'https://api.twitch.tv/kraken/streams/followed?limit=100&stream_type=all' \
-H 'accept: application/vnd.twitchtv.v5+json' \
-H "$cookie" \
-H "$client_id" | json2 | sort -n | awk -F'=' '
-H "$client_id" | json2 | sort -n | awk '
function trunc(s,L) {
e = length(s) > L ? "…" : "";
return (substr(s, 0, L -(e ? 1 : 0)) e);
}
$1~/\/game$/{game=$2}
$1~/\/channel\/status$/{status=$2}
$1~/\/channel\/name$/{name=$2}
$1~/\/viewers$/{printf "\x1b[90m%5s\x1b[0m \x1b[97m%-25s\x1b[0m %s\n \x1b[1m%s\x1b[0m\n",$2,name,trunc(game,48),status}
'
$1~/\/game$/{game=substr($2,2)}
$1~/\/channel\/status$/{status=substr($2,2)}
$1~/\/channel\/name$/{name=substr($2,2)}
$1~/\/viewers$/{
viewers=substr($2,2);
printf "\x1b[90m%5s\x1b[0m \x1b[97m%-25s\x1b[0m %s\n \x1b[1m%s\x1b[0m\n",
viewers, name, trunc(game, 48), status;
}
' FPAT='(^[^=]+)|(=.*)'