diff options
author | Joe Rayhawk <jrayhawk@omgwallhack.org> | 2016-05-22 20:36:46 -0700 |
---|---|---|
committer | Joe Rayhawk <jrayhawk@omgwallhack.org> | 2016-05-22 20:36:46 -0700 |
commit | 63ae6eea839d2ee7dce690f30d6acffb29b7fe5b (patch) | |
tree | a79cabfe10a609f5fa3a9152222232c1d22c7ec8 /lstwitchfollowers.rb | |
parent | f86d3c75c10b312508e9e2677e7ffa456109751e (diff) | |
download | twitchtools-63ae6eea839d2ee7dce690f30d6acffb29b7fe5b.tar.gz twitchtools-63ae6eea839d2ee7dce690f30d6acffb29b7fe5b.zip |
lstwitchfollowers: add follow stats, robustify a bit
Diffstat (limited to 'lstwitchfollowers.rb')
-rwxr-xr-x | lstwitchfollowers.rb | 18 |
1 files changed, 10 insertions, 8 deletions
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 |