Skip to content

Instantly share code, notes, and snippets.

@itochan
Created May 15, 2012 15:46
Show Gist options
  • Save itochan/2702782 to your computer and use it in GitHub Desktop.
Save itochan/2702782 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require "net/http"
require "rexml/document"
require "growl"
XML_PATH = "http://www.j-wave.co.jp/top/xml/now_on_air_song.xml"
TITLE = "ソラガール"
ARTIST = "PACO"
Growl.notify do
self.title = "soragirl.rb"
self.message = "running soragirl"
end
prev_song = ""
loop do
source = Net::HTTP.get(URI.parse(XML_PATH))
xml = REXML::Document.new(source)
data = xml.elements["now_on_air_song/data"].attributes
now_song = data["information"].gsub(/\s\d\d:\d\d/, "")
unless now_song == prev_song
puts "#{Time.now.to_s}: #{now_song}"
if now_song == "「#{TITLE}」 #{ARTIST}"
Growl.notify do
self.title = "soragirl.rb"
self.message = "Now Playing: #{now_song}"
end
end
end
prev_song = now_song
sleep 20
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment