Created
May 14, 2009 19:30
-
-
Save snaka/111840 to your computer and use it in GitHub Desktop.
livedoor Reader unread subscribes count notifier
This file contains hidden or 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
| #!/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