Skip to content

Instantly share code, notes, and snippets.

@tomohiro
Created November 30, 2009 02:58
Show Gist options
  • Save tomohiro/245236 to your computer and use it in GitHub Desktop.
Save tomohiro/245236 to your computer and use it in GitHub Desktop.
Gmail の未読件数を取得するスクリプト
#!/usr/bin/env ruby
#
# ex.
# ./gmail_check.rb -a your_account -p your_password
#
require 'optparse'
require 'net/https'
require 'rubygems'
require 'nokogiri'
ARGV.options do |o|
o.on('-a', '--account ACCOUNT', 'Gmail Account. ') { |v| @account = v }
o.on('-p', '--password PASSWORD', 'Gmail Password') { |v| @password = v }
o.parse!
end
proxy = ENV['https_proxy'] || ENV['http_proxy']
https = Net::HTTP::Proxy(URI.parse(proxy).host, URI.parse(proxy).port).new('mail.google.com', 443)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new('/mail/feed/atom')
request.basic_auth(@account, @password)
responce = https.request(request).body
xml = Nokogiri::XML(responce)
puts (xml/'fullcount').text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment