Created
September 1, 2012 21:50
-
-
Save dbasch/3588581 to your computer and use it in GitHub Desktop.
Dump the ADN Global feed to your terminal
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 | |
%w(open-uri json time).each { |dependency| require dependency } | |
#quick hack to see the ADN Global Timeline scrolling on your terminal | |
#by @dbasch - modify at will | |
toSleep = 3 | |
color = 0 | |
start = Time.now | |
ids, old_ids = [], [] | |
token = "REPLACE THIS BY A VALID TOKEN" | |
while true | |
global = JSON.load open("https://alpha-api.app.net/stream/0/posts/stream/global", "Authorization" => "Bearer " + token) | |
global.each do |post| | |
ids << post['id'] | |
printf "%c[1;30m\n---\n%s %c[1;%sm%s", 27, post['user']['username'], 27, ['31', '32', '34'][color], post['text'] if not old_ids.include? post['id'] | |
end | |
intersection = old_ids & ids | |
color = (color + 1) % 3 if intersection.size < 20 | |
toSleep += 1 if intersection.size > 5 and toSleep < 20 | |
toSleep = 0 if intersection.size == 0 | |
old_ids = ids | |
ids = [] | |
if Time.now - start > 10 | |
printf "\n\n%c[1;30m--- %s ---\n", 27, Time.now.to_s | |
start = Time.now | |
end | |
sleep toSleep | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment