Skip to content

Instantly share code, notes, and snippets.

@iseebi
Created August 23, 2009 05:26
Show Gist options
  • Save iseebi/173168 to your computer and use it in GitHub Desktop.
Save iseebi/173168 to your computer and use it in GitHub Desktop.
Utasuki JOYSOUND recent sing song post to Twitter
require 'rubygems'
require 'mechanize'
require 'hpricot'
require 'twitter'
JOYSOUND_ID_MAIL = ''
JOYSOUND_ID_PASS = ''
TWITTER_ID = ''
TWITTER_PASS = ''
FLAG_FILE = 'utasukipost.dat'
#---------------------------------------------------------------------------------------------------
agent = WWW::Mechanize.new
page = agent.get('http://joysound.com/')
page.forms[1].fields[0].value = JOYSOUND_ID_MAIL
page.forms[1].fields[1].value = JOYSOUND_ID_PASS
page = page.forms[1].submit
page = page.links[0].click
page = agent.get('http://joysound.com/ex/utasuki/mypage/singhistory/index.htm')
doc = Hpricot(page.body)
list = []
(((doc/"div.listLv2")/:tbody)/:tr).each do |tr|
tds = tr/:td
date = tds[0].inner_html
song = (tds[1]/:a).inner_html
singer = (tds[2]/:a).inner_html
list.push({:date => date, :song => song, :singer => singer})
end
#---------------------------------------------------------------------------------------------------
last_sing = list[0]
file_flag_str = ''
last_flag_str = "#{last_sing[:date]}\t#{last_sing[:song]}\t#{last_sing[:singer]}"
if File.exists?(FLAG_FILE)
File.open(FLAG_FILE, 'r') do |f|
file_flag_str = f.read
end
else
file_flag_str = ''
end
if file_flag_str != last_flag_str
twitter = Twitter::Client.new(:login => TWITTER_ID, :password => TWITTER_PASS)
twitter.status(:post, "歌った ♪#{last_sing[:song]}/#{last_sing[:singer]}")
File.open(FLAG_FILE, 'w') do |f|
f.write(last_flag_str)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment