From 0243eb33dd4a039cce10422caf42db513e9e4bbc Mon Sep 17 00:00:00 2001 From: Connor Date: Sun, 30 Jul 2017 19:41:51 -0700 Subject: [PATCH] --- following | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/following b/following index d134af6..e81299e 100644 --- a/following +++ b/following @@ -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='(^[^=]+)|(=.*)'