Last active
April 20, 2016 12:51
-
-
Save erenhatirnaz/7979072af70a647d716e026d50d5c3e3 to your computer and use it in GitHub Desktop.
Shows live streamers that you followed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/https' | |
require 'uri' | |
require 'json' | |
require 'colorize' | |
def get(url) | |
url = URI.parse(url) | |
req = Net::HTTP::Get.new(url.to_s) | |
http = Net::HTTP.new(url.host, url.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
response = http.request(req) | |
JSON.parse(response.body, { :symbolize_names => true }) | |
end | |
username = "[WRITE YOUR TWITCH USERNAME HERE]" | |
followCount = get("https://api.twitch.tv/kraken/users/#{ username }/follows/channels")[:_total] | |
userFollows = get("https://api.twitch.tv/kraken/users/#{ username }/follows/channels?limit=#{ followCount }")[:follows] | |
userFollowsChannelNames = userFollows.map { |channel| channel[:channel][:display_name] } | |
streamers = get("https://api.twitch.tv/kraken/streams?channel=#{ userFollowsChannelNames.join(',') }&limit=#{ followCount }") | |
print "Total live streamer: #{ streamers[:_total].to_s }\n-----------------------\n".colorize(:yellow) | |
for streamer in streamers[:streams] | |
if !streamer[:_id].nil? | |
print streamer[:channel][:display_name].red + " | " + streamer[:channel][:game].blue + " | " + streamer[:channel][:url].green + "\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment