Skip to content

Instantly share code, notes, and snippets.

@naoto
Last active December 13, 2015 18:58
Show Gist options
  • Save naoto/4959197 to your computer and use it in GitHub Desktop.
Save naoto/4959197 to your computer and use it in GitHub Desktop.
blink1 で mail を check する
#!/usr/bin/env ruby
require 'blink1'
require 'net/pop'
module MailChecker
class Blink
def self.start
self.new(ENV['pop_server'], ENV['pop_port'], ENV['username'], ENV['password']).run
end
def initialize(server, port, username, password)
@config = {
server: server,
username: username,
password: password,
port: port
}
@blink = Blink1.new
@blink.open
end
def run
loop do
if mail?
blink_off
else
blink_flash
end
sleep 300
end
end
private
def mail?
pop = Net::POP3.new(@config[:server], @config[:port])
pop.start(@config[:username], @config[:password])
count = pop.mails.count
pop.finish
count == 0
end
def blink_flash
@blink.set_rgb(255,0,0)
end
def blink_off
@blink.set_rgb(0,0,0)
end
end
end
$0 == __FILE__
MailChecker::Blink.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment