Skip to content

Instantly share code, notes, and snippets.

@ymrl
Created July 18, 2011 19:27
Show Gist options
  • Save ymrl/1090404 to your computer and use it in GitHub Desktop.
Save ymrl/1090404 to your computer and use it in GitHub Desktop.
togetterからTweets引っ張ってくる的な
require 'nokogiri'
require 'open-uri'
require 'kconv'
def show_tweet tweets
tweets.each do |t|
screen_name = t.css('.status_name').text
user_icon = t.css('.twttrimg').first.attributes["src"].value
tweet_time = Time.parse(t.css('.status_right a')[1].text)
tweet_link = t.css('.status_right a')[1].attributes['href'].text
tweet_body = t.css('.tweet').text
puts "#{screen_name} : #{tweet_body}\n\t#{tweet_time}\n\t#{tweet_link}\n\t#{user_icon}"
end
end
def get_togetter u
url = nil
id = nil
matched = u.match(/^http:\/\/(?:www\.)?(togetter\.com\/li\/(\d+))/)
if matched
url = "http://#{matched[1]}"
id = matched[2]
else
raise Exception
end
doc = Nokogiri::HTML(open(url))
more_button = doc.css('.rich_button[onclick^="tgtr.more"]').first
show_tweet doc.css('.tweet_box .type_tweet')
page = 2
while more_button
more = Nokogiri::HTML(open("http://togetter.com/api/moreTweets/#{id}?page=#{page}","Referer" => url).read.toutf8)
more_button = more.css('.rich_button[onclick^="tgtr.more"]').first
show_tweet more.css('.type_tweet')
page += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment