Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'cgi'
require 'redis'
require 'httparty'
auth_token = YOUR PINBOARD TOKEN
pocket_username = YOUR POCKET USERNAME
page = Nokogiri::HTML(open("https://getpocket.com/@#{pocket_username}"))
redis = Redis.new
page.css(".sprofile-post").each do |post|
url = CGI::parse(URI.parse(post.css("a.sprofile-article-link")[0]['href']).query)["url"][0]
unless redis.sismember("pocketboard", url)
# post to pinboard
description = URI::escape(post.css(".sprofile-article-title").text())
extended = post.css(".sprofile-attribution-quote").text()
extended = "\"" + extended + "\"" if extended.length > 0
comment = post.css(".sprofile-attribution-comment").text()
if comment.length > 0
extended = comment + ": " + extended
end
extended = URI::escape(extended)
response = HTTParty.get("https://api.pinboard.in/v1/posts/add?auth_token=#{auth_token}&url=#{URI::escape(url)}&description=#{description}&extended=#{extended}")
if response["result"]["code"] == "done"
redis.sadd("pocketboard", url)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment