Skip to content

Instantly share code, notes, and snippets.

@snaka
Created May 14, 2009 19:30
Show Gist options
  • Select an option

  • Save snaka/111840 to your computer and use it in GitHub Desktop.

Select an option

Save snaka/111840 to your computer and use it in GitHub Desktop.
livedoor Reader unread subscribes count notifier
#!/usr/bin/ruby
# livedoorReader未読数更新チェッカ
#
require 'net/http'
require 'pstore'
require 'rubygems'
require 'pit'
require 'ruby_gntp'
$tweeted = {}
$growl = GNTP.new
$growl.register({
:app_name => "ldr_notifier",
:notifications => [{ :name => "Notify", :enabled => true },
{ :name => "Error", :enabled => true }]
})
config = Pit.get("livedoor", :require => {
"user" => "your livedoor user id"
})
unread = 0
PStore.new(Dir.pwd + '/store').transaction do |store|
unread = store['unread'] || 0
puts "restore unread #{unread}"
Net::HTTP.version_1_2
proxy_host, proxy_port = (ENV["HTTP_PROXY"] || '').sub(/http:\/\//, '').split(':')
Net::HTTP::Proxy(proxy_host, proxy_port).start('rpc.reader.livedoor.com') do |http|
res = http.get("/notify?user=#{config['user']}")
puts "/notify?user=#{config['user']}" #if $DEBUG
if res.code != '200'
$growl.notify({
:name => "Error",
:title => "Error occurd",
:test => "Can not get unread count!"
})
return
end
unread = res.body.split(/\|/)[1]
end
$growl.notify({
:name => "Notify",
:title => "Unread subscribes",
:text => "#{unread}"
})
puts "store unread #{unread}"
store['unread'] = unread
end
# vim: ts=2 sw=2 et fdm=marker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment