Skip to content

Instantly share code, notes, and snippets.

@tily
Created March 6, 2011 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tily/857331 to your computer and use it in GitHub Desktop.
Save tily/857331 to your computer and use it in GitHub Desktop.
無理矢理ニュースっぽく変換するやつ
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