Skip to content

Instantly share code, notes, and snippets.

@ckozus
Created September 1, 2008 00:35
Show Gist options
  • Save ckozus/8243 to your computer and use it in GitHub Desktop.
Save ckozus/8243 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'open-uri'
require 'feed-normalizer'
require 'mirrored'
require 'json'
class YahooTermExtractor
def self.api_id=(value)
@@api_id = value
end
def self.terms(context, query)
url = URI.parse('http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction')
post_args = {'appid' => @@api_id, 'context' => context, 'query' => query, 'output' => 'json'}
begin
response, data = Net::HTTP.post_form(url, post_args)
parsed_data = JSON.parse(data)
parsed_data['ResultSet']['Result'] if parsed_data
rescue Exception
return nil
end
end
end
class SharedItemsBookmarker
def initialize(feed_url, username, password)
@feed_url = feed_url
Mirrored::Base.establish_connection(:delicious, username, password)
@username = username
@password = password
end
def post_bookmarks!
feed = FeedNormalizer::FeedNormalizer.parse open(@feed_url)
feed.entries.each do |entry|
bookmark_entry!(entry)
end
end
def bookmark_entry!(entry)
puts "bookmarking: #{entry.title} #{entry.url}"
if Mirrored::Post.find(:get, :url => entry.url).empty?
post = Mirrored::Post.new
post.url = entry.url
post.description = entry.title
terms = YahooTermExtractor.terms(entry.content, entry.title)
post.tags = terms if terms
puts post.save ? 'Saved' : "ERROR!"
end
end
end
# Change this parameters
# You can get a new one here: http://developer.yahoo.com/wsregapp/
YahooTermExtractor.api_id = "your-app-api-id"
# Change with your own feed url
feed_url = "http://www.google.com/reader/public/atom/user/16082959894154758135/state/com.google/broadcast"
# Change with your delicious' username and password
sib = SharedItemsBookmarker.new(feed_url, 'username', 'password')
# Do the magic!
sib.post_bookmarks!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment