Skip to content

Instantly share code, notes, and snippets.

@andrewpbrett
Created July 14, 2016 08:58
Show Gist options
  • Save andrewpbrett/a6dd3bde020b2ec2b5b1157008c734c7 to your computer and use it in GitHub Desktop.
Save andrewpbrett/a6dd3bde020b2ec2b5b1157008c734c7 to your computer and use it in GitHub Desktop.
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