Created
November 12, 2008 08:41
-
-
Save koyachi/24111 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'rubygems' | |
require 'fuc' | |
require 'tinyurl' | |
$tinyurl = Tinyurl.new('http://google.com'); | |
def resolve_tinyurl(url) | |
$tinyurl.url = url | |
($tinyurl.is_tiny?) ? $tinyurl.resolve(url) : url | |
end | |
module TwitterProcesser | |
module TimelineGetter | |
def process(url_entry) | |
messages = nokogiri(url_entry.body).xpath('//td[@class="status-body"]') | |
messages.each do |m| | |
entry_urls = [m.xpath('div/span/a[@class="entry-date"]')[0]].map {|u| | |
push_url(u['href'], url_entry.url, '') | |
} | |
end | |
end | |
end | |
# twitter 指定ユーザfavourites表示 | |
class FavouritesListGetter < Fuc::Processer | |
include TimelineGetter | |
def match(url_entry) | |
url_entry.url =~ %r!http://twitter.com/.*?/favourites! | |
end | |
end | |
class UserTimelineGetter < Fuc::Processer | |
include TimelineGetter | |
def match(url_entry) | |
url_entry.url =~ %r!^http://twitter.com/[^/]*?$! | |
end | |
end | |
# 各メッセージエントリ内容取得 | |
class EntryGetter < Fuc::Processer | |
def match(url_entry) | |
url_entry.url =~ %r!http://twitter.com/.*?/status/! | |
end | |
def process(url_entry) | |
desc = nokogiri(url_entry.body).xpath('//div[@class="desc"]')[0] | |
user = desc.xpath('div[@class="user-info clear"]/div[@class="screen-name"]/a')[0].text | |
extracted_msg = extract_message_url(desc.xpath('div[@class="desc-inner"]/p')[0].inner_html.strip) | |
log [user, extracted_msg].join(":") | |
urls = URI.extract(extracted_msg, %w[http https]).map {|u| | |
push_url(resolve_tinyurl(u), url_entry.url, extracted_msg, 'notify') | |
} | |
end | |
def extract_message_url(message) | |
message.gsub(%r!<a href="(.*?)" rel="nofollow" target="_blank">.*?</a>!) {$1} | |
end | |
end | |
end | |
Fuc.register_process(Fuc::Processer::NotifyURLsVIA, true, 'normal') | |
Fuc.output_processer_log(Fuc::Processer::NotifyURLsVIA) | |
#users_favourites = %w[fuba youpy] | |
#Fuc.run(users_favourites.map {|user| "http://twitter.com/#{user}/favourites"}) | |
#user_timelines = %w[33 yuiseki] | |
user_timelines = %w[33] | |
Fuc.run(user_timelines.map {|user| "http://twitter.com/#{user}"}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment