Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kinopyo/1053165 to your computer and use it in GitHub Desktop.
Save kinopyo/1053165 to your computer and use it in GitHub Desktop.
Count of Google Reader subscribers
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'rexml/document'
require 'mechanize'
# ------------------------
YOUR_GOOGLE_ACCOUNT = 'your@gmail.com'
YOUR_GOOGLE_PASSWORD = 'your_password'
RSSES = ["http://hoge.com/?feed=rss2",
"http://hoge.com/?feed=atom"]
# ------------------------
LOGIN_URL = "https://www.google.com/accounts/ServiceLogin?hl=ja&continue=http://www.google.co.jp/"
agent = Mechanize.new
form = agent.get(LOGIN_URL).forms.first
form.Email = YOUR_GOOGLE_ACCOUNT
form.Passwd = YOUR_GOOGLE_PASSWORD
agent.submit(form)
BASE_PRE = "http://www.google.com/reader/api/0/stream/details?s=feed/"
BASE_POST = "&output=xml&fetchTrends=false"
sum = 0
RSSES.each do |r|
page = agent.get("#{BASE_PRE}#{r}#{BASE_POST}")
doc = REXML::Document.new(page.body)
doc.root.elements.each do |e|
if (e.attributes['name'] == 'subscribers')
sum = sum + e.text.gsub(",", "").to_i
end
end
end
puts sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment