Created
August 1, 2017 09:15
-
-
Save ghys/16445cce47c868dd75bf52c030edfb0d to your computer and use it in GitHub Desktop.
Script to collect Discourse stats about HABPanel categories on community.openhab.org
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
require 'net/http' | |
require 'json' | |
$topics = 0 | |
$posts = 0 | |
$page = 0 | |
$views = 0 | |
$likes = 0 | |
def get_stats(uri) | |
puts "fetching: #{uri}" | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Get.new uri | |
response = http.request request | |
result = JSON.parse(response.body) | |
$topics += result['topic_list']['topics'].length | |
result['topic_list']['topics'].each { |topic| | |
$posts += topic['posts_count'] | |
$views += topic['views'] | |
$likes += topic['like_count'] | |
} | |
$page += 1 | |
return result['topic_list']['more_topics_url'] | |
end | |
uri = URI('https://community.openhab.org/c/apps-services/habpanel.json') | |
while uri do | |
more_topics = get_stats uri | |
if more_topics then | |
uri = URI("https://community.openhab.org/c/apps-services/habpanel.json?page=#{$page}") | |
else | |
uri = nil | |
end | |
end | |
$page = 0 | |
examples_uri = URI('https://community.openhab.org/c/tutorials-examples/habpanel-examples.json') | |
get_stats examples_uri | |
puts "topics=#{$topics} posts=#{$posts} views=#{$views} likes=#{$likes}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment