Created
October 21, 2009 05:45
-
-
Save rtanglao/214903 to your computer and use it in GitHub Desktop.
open untagged Mozilla Messaging Get Satisfaction topics
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 | |
require 'json' | |
require 'net/http' | |
require 'pp' | |
require 'Time' | |
require 'launchy' | |
# Launchy.open("http://stackoverflow.com") | |
def getResponse(url) | |
http = Net::HTTP.new("api.getsatisfaction.com",80) | |
url = "/" + url | |
resp, data = http.get(url, nil) | |
if resp.code != "200" | |
puts "Error: #{resp.code}" | |
return "" | |
end | |
result = JSON.parse(data) | |
return result | |
end | |
if ARGV.length < 6 | |
puts "usage: #{$0} yyyy mm dd yyyy mmm dd" | |
exit | |
end | |
metrics_start = Time.utc(ARGV[0], ARGV[1], ARGV[2], 0, 0) | |
metrics_start -= 1 | |
metrics_stop = Time.utc(ARGV[3], ARGV[4], ARGV[5], 23, 59) | |
metrics_stop += 1 | |
topic_page = 1 | |
end_program = false | |
employees = getResponse("companies/mozilla_messaging/employees.json") | |
while true | |
get_topic_url = "companies/mozilla_messaging/topics.json?sort=recently_created&page=" << "%d" % topic_page << "&limit=30" | |
printf(STDERR, "get_topic_url") | |
topics = getResponse(get_topic_url) | |
topics["data"].each do|topic| | |
url = topic["at_sfn"] | |
created_at = Time.parse(topic["created_at"]) | |
created_at = created_at.utc | |
most_recent_activity = topic["most_recent_activity"] | |
printf(STDERR, "TOPIC created_at:%s\n",created_at) | |
printf(STDERR, "TOPIC most_recent_activity:%s\n",most_recent_activity) | |
if (created_at <=> (metrics_start + 1)) == -1 | |
printf(STDERR, "ending program\n") | |
end_program = true | |
break | |
end | |
printf(STDERR, "START*** of topic\n") | |
PP::pp(topic,$stderr) | |
printf(STDERR, "\nEND*** of topic\n") | |
if most_recent_activity == "create" | |
printf(STDERR, "Opening URL:%s\n", url) | |
Launchy.open(url) | |
end | |
end | |
if end_program | |
break | |
end | |
topic_page += 1 | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment