Created
June 8, 2013 16:21
-
-
Save jeena/5735707 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 -wKU | |
require 'net/http' | |
require 'uri' | |
require 'openssl' | |
require 'json' | |
require 'cgi' | |
require 'rack/utils' | |
uri = URI("https://app.tent.is/api/posts?post_types=https%3A%2F%2Ftent.io%2Ftypes%2Fpost%2Fstatus%2Fv0.1.0&limit=200") | |
https = Net::HTTP.new(uri.hostname, uri.port) | |
https.use_ssl = true | |
https.ssl_timeout = 2 | |
https.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
https.verify_depth = 2 | |
apps = {} | |
before_id = "" | |
before_id_entity = "" | |
date = "" | |
while true | |
https.start do |http| | |
request = Net::HTTP::Get.new(uri.path + "?" + uri.query) | |
response = https.request(request) | |
js = JSON.parse(response.body) | |
js.each do |j| | |
apps[j["app"]["name"].to_sym] = 0 if apps[j["app"]["name"].to_sym].nil? | |
apps[j["app"]["name"].to_sym] += 1 | |
end | |
before_id = js.last["id"] | |
before_id_entity = js.last["entity"] | |
date = Time.at js.last["published_at"] | |
end | |
query = uri.query.split("&").map {|s| k,v = s.split("="); [k, v] }.inject({}){|m,e| m[e[0]] = e[1]; m} | |
query[:before_id] = before_id | |
query[:before_id_entity] = before_id_entity | |
uri.query = query.map {|k,v| k.to_s + "=" + v.to_s}.join("&") | |
puts "--------------------- " + date.to_s | |
puts apps | |
end | |
# --------------------- 2013-06-07 18:31:52 +0200 | |
# {:TentStatus=>79, :"Bungloo on OS X"=>80, :"Trion on iPad"=>7, :"Trion on iPhone"=>5, :splatmonstar=>2, :"Bungloo on Windows"=>15, :"Bungloo on Linux"=>11, :Zelten=>1} | |
# ... | |
# --------------------- 2013-05-02 23:51:02 +0200 | |
# {:TentStatus=>1489, :"Bungloo on OS X"=>1221, :"Trion on iPad"=>73, :"Trion on iPhone"=>183, :splatmonstar=>93, :"Bungloo on Windows"=>194, :"Bungloo on Linux"=>151, :Zelten=>1, :"testing voting app"=>3, :"Bivy for iOS"=>140, :"Project Bonfire"=>23, :tentmonstar=>9, :"tentocracy in titanium"=>1, :"TrionBeta on iPhone"=>2, :"hash-task"=>11, :"TentStatus Standalone"=>6} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment