diff options
author | Joe Rayhawk <jrayhawk@omgwallhack.org> | 2016-09-15 00:10:14 -0700 |
---|---|---|
committer | Joe Rayhawk <jrayhawk@omgwallhack.org> | 2016-09-15 00:10:14 -0700 |
commit | aed3d1114c4b62e0c55a68fe92022b2a66798681 (patch) | |
tree | d4ed5703436ac1e62aee86e6876d99e285d9390e /lstwitchfollowers.rb | |
parent | 074e60dfb020245e1ae6148b22d1faeaae6dd965 (diff) | |
download | twitchtools-aed3d1114c4b62e0c55a68fe92022b2a66798681.tar.gz twitchtools-aed3d1114c4b62e0c55a68fe92022b2a66798681.zip |
lstwitchfollowers: add client_id support
Diffstat (limited to 'lstwitchfollowers.rb')
-rwxr-xr-x | lstwitchfollowers.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lstwitchfollowers.rb b/lstwitchfollowers.rb index 69d8ec2..4ee51d6 100755 --- a/lstwitchfollowers.rb +++ b/lstwitchfollowers.rb @@ -8,6 +8,12 @@ user = String.new user = URI.escape(ARGV[0]) +confdir = Dir.home + '/.config/twitch/' +ENV['APPDATA'] && confdir = ENV['APPDATA'] + "\\twitch\\" +ENV['XDG_CONFIG_HOME'] && confdir = ENV['XDG_CONFIG_HOME'] + '/twitch/' + +client_id = IO.read( confdir + 'client_id' ).chomp + http = Net::HTTP.new('api.twitch.tv', 443) http.use_ssl = true #http.verify_mode = OpenSSL::SSL::VERIFY_NONE @@ -19,14 +25,14 @@ if width < 97 width=97 end -def followers(http, path, key, width) +def followers(http, path, key, width, client_id) total = 100 offset = 0 while offset <= total - response = JSON.parse(http.request(Net::HTTP::Get.new("#{path}?limit=100&offset=#{offset}")).body) + response = JSON.parse(http.request(Net::HTTP::Get.new("#{path}?limit=100&offset=#{offset}&client_id=#{client_id}")).body) total = response['_total'] for channel in response['follows'] name = channel[key]['name'] @@ -36,7 +42,7 @@ def followers(http, path, key, width) # print(" #{stream['game']} #{stream['channel']['status']}") # Curses.cols else - profile = JSON.parse(http.request(Net::HTTP::Get.new("/kraken/channels/#{name}")).body) + profile = JSON.parse(http.request(Net::HTTP::Get.new("/kraken/channels/#{name}?client_id=#{client_id}")).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 @@ -48,8 +54,8 @@ end print("Following:\n\n") -followers(http, "/kraken/users/#{user}/follows/channels", 'channel', width) +followers(http, "/kraken/users/#{user}/follows/channels", 'channel', width, client_id) print("\nFollowed by:\n\n") -followers(http, "/kraken/channels/#{user}/follows", 'user', width) +followers(http, "/kraken/channels/#{user}/follows", 'user', width, client_id) |