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 /lstwitch.rb | |
download | twitchtools-d7eef063a7d993dcd91a701f151597a678b09190.tar.gz twitchtools-d7eef063a7d993dcd91a701f151597a678b09190.zip |
twitchtools: initial commit
Diffstat (limited to 'lstwitch.rb')
-rwxr-xr-x | lstwitch.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lstwitch.rb b/lstwitch.rb new file mode 100755 index 0000000..92e5255 --- /dev/null +++ b/lstwitch.rb @@ -0,0 +1,33 @@ +#!/usr/bin/ruby + +require 'json' +require 'net/http' + +game = String.new + +unless ARGV.empty? + game = "&game=#{URI.escape(ARGV[0])}" + if ARGV[0] == 'APB' or ARGV[0] == 'apb' + game = "&game=APB%20Reloaded" + end +end + +http = Net::HTTP.new('api.twitch.tv', 443) +http.use_ssl = true +#http.verify_mode = OpenSSL::SSL::VERIFY_NONE + +offset = 0 +total = 1 + +width = `stty size`.split[1].to_i + +while offset < total + + response = JSON.parse(http.request(Net::HTTP::Get.new("/kraken/streams/?offset=#{offset}#{game}")).body) + total = response["_total"] + for stream in response['streams'] + 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/,'') ) + end + offset += 100 + +end |