diff options
author | Joe Rayhawk <jrayhawk@omgwallhack.org> | 2015-10-21 16:47:05 -0700 |
---|---|---|
committer | Joe Rayhawk <jrayhawk@omgwallhack.org> | 2015-10-21 16:47:05 -0700 |
commit | d7eef063a7d993dcd91a701f151597a678b09190 (patch) | |
tree | 22968b9e611614266bae49d451ad1ff6aea3038e /lstwitchfollowers.rb | |
download | twitchtools-d7eef063a7d993dcd91a701f151597a678b09190.tar.gz twitchtools-d7eef063a7d993dcd91a701f151597a678b09190.zip |
twitchtools: initial commit
Diffstat (limited to 'lstwitchfollowers.rb')
-rwxr-xr-x | lstwitchfollowers.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lstwitchfollowers.rb b/lstwitchfollowers.rb new file mode 100755 index 0000000..bb762a3 --- /dev/null +++ b/lstwitchfollowers.rb @@ -0,0 +1,49 @@ +#!/usr/bin/ruby + +# the 'streams' api much more efficient but requires authentication + +require 'json' +require 'net/http' + +user = String.new + +user = URI.escape(ARGV[0]) + +http = Net::HTTP.new('api.twitch.tv', 443) +http.use_ssl = true +#http.verify_mode = OpenSSL::SSL::VERIFY_NONE +http.read_timeout = 500 + +width = `stty size`.split[1].to_i + +def followers(http, path, key, width) + + followed = { '_total' => 0 } + offset = 0 + + while offset <= followed['_total'] + + for channel in JSON.parse(http.request(Net::HTTP::Get.new("#{path}?limit=100&offset=#{offset}")).body)['follows'] + name = channel[key]['display_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/,'') ) +# print(" #{stream['game']} #{stream['channel']['status']}") +# Curses.cols + else + print("twitch.tv/#{name}\n") + end + end + offset += 100 + + end + +end + +print("Following:\n\n") + +followers(http, "/kraken/users/#{user}/follows/channels", 'channel', width) + +print("\nFollowed by:\n\n") + +followers(http, "/kraken/channels/#{user}/follows", 'user', width) |