Created
March 6, 2011 14:30
-
-
Save tily/857331 to your computer and use it in GitHub Desktop.
無理矢理ニュースっぽく変換するやつ
This file contains 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
require 'open-uri' | |
require 'rubygems' | |
require 'oauth/cli/twitter' | |
require 'nokogiri' | |
URL = 'http://headlines.yahoo.co.jp/hl' | |
REGEXP = /「(.*)」/ | |
abort 'Usage: ruby twitter_news.rb ねむい' if ARGV.size == 0 | |
doc = Nokogiri::HTML.parse(open(URL)) | |
texts = doc.xpath('//a/text()') | |
texts = texts.select{|t| t.to_s.match(REGEXP) } | |
status = texts[rand(texts.length)].to_s | |
status.gsub!(REGEXP, "「#{ARGV[0]}」") | |
token = OAuth::CLI::Twitter.get_access_token(:pit => 'twitter-news') | |
token.post('http://twitter.com/statuses/update.json', 'status'=> status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment