summaryrefslogtreecommitdiff
path: root/lstwitchfollowers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lstwitchfollowers.rb')
-rwxr-xr-xlstwitchfollowers.rb18
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