From 63ae6eea839d2ee7dce690f30d6acffb29b7fe5b Mon Sep 17 00:00:00 2001 From: Joe Rayhawk Date: Sun, 22 May 2016 20:36:46 -0700 Subject: lstwitchfollowers: add follow stats, robustify a bit --- lstwitchfollowers.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lstwitchfollowers.rb') diff --git a/lstwitchfollowers.rb b/lstwitchfollowers.rb index bb762a3..296b4e9 100755 --- a/lstwitchfollowers.rb +++ b/lstwitchfollowers.rb @@ -1,7 +1,6 @@ #!/usr/bin/ruby -# the 'streams' api much more efficient but requires authentication - +#require 'curses' require 'json' require 'net/http' @@ -18,20 +17,23 @@ width = `stty size`.split[1].to_i def followers(http, path, key, width) - followed = { '_total' => 0 } + total = 100 offset = 0 - while offset <= followed['_total'] + while offset <= total - for channel in JSON.parse(http.request(Net::HTTP::Get.new("#{path}?limit=100&offset=#{offset}")).body)['follows'] - name = channel[key]['display_name'] + response = JSON.parse(http.request(Net::HTTP::Get.new("#{path}?limit=100&offset=#{offset}")).body) + total = response['_total'] + for channel in response['follows'] + name = channel[key]['name'] stream = JSON.parse(http.request(Net::HTTP::Get.new("/kraken/streams/#{name}")).body)['stream'] if stream - printf( "%-45s %-36s %6i %-.#{width-46-37-7}s\n", stream['channel']['url'].to_s, stream['channel']['game'].to_s, stream['viewers'], stream['channel']['status'].to_s.gsub(/\n/,'') ) + printf( "%-45s %-36s %6i %6i %-.#{width-46-37-7-7}s\n", "ONLINE twitch.tv/#{name}", stream['channel']['game'].to_s, stream['viewers'], stream['channel']['followers'], stream['channel']['status'].to_s.gsub(/\n/,'') ) # print(" #{stream['game']} #{stream['channel']['status']}") # Curses.cols else - print("twitch.tv/#{name}\n") + profile = JSON.parse(http.request(Net::HTTP::Get.new("/kraken/channels/#{name}")).body) + printf( "%-45s %-36s %6i %6i %-.#{width-46-37-7-7}s\n", "offline twitch.tv/#{name}", profile['game'].to_s, "0", profile['followers'], profile['status'].to_s.gsub(/\n/,'') ) end end offset += 100 -- cgit v1.2.3