Skip to content

Instantly share code, notes, and snippets.

@tommorris
Created December 2, 2010 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommorris/726013 to your computer and use it in GitHub Desktop.
Save tommorris/726013 to your computer and use it in GitHub Desktop.
require "rubygems"
require "nokogiri"
require "open-uri"
$hash = {}
def load_from_api(num)
# replace 'blog.tommorris.org' with your tumblr blog URL.
data = Nokogiri::XML(open("http://blog.tommorris.org/api/read?num=50&start=#{num}"))
tags = data.xpath("//tag").map {|i| i.text }
# this initializes the hash key to zero if it isn't already set, then increments
tags.each {|i| $hash[i] ||= 0; $hash[i] += 1 }
end
# replace '108' with the number of posts you have made divided by 50 - rounded up.
# your total # of posts is on your dashboard
(0..108).to_a.each {|n|
load_from_api(n * 50)
}
fh = File.open(File.expand_path("~/tags.txt"), "w")
# reverse sort by value
$hash = $hash.sort {|x,y| y[1] <=> x[0] }
$hash.each do |line|
fh.write("#{line[0]} -- #{line[1].to_s}\n")
end
fh.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment