Last active
June 4, 2018 23:56
-
-
Save pdxmph/3c822098420e30db600300ca4006f17d to your computer and use it in GitHub Desktop.
Fix Pinboard bookmarks with URLs for titles
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 | |
require 'pinboard' | |
require 'nokogiri' | |
require 'open-uri' | |
# get your Pinboard API token here: https://pinboard.in/settings/password | |
pinboard = Pinboard::Client.new(:token => 'XXXXXXXXXXXXXX') | |
posts = pinboard.posts(:results => 50) | |
def title_clean(post) | |
open(post.href) do |f| | |
doc = Nokogiri::HTML(f) | |
new_post_description = doc.at_css('title').text | |
return new_post_description | |
end | |
end | |
posts.each do |p| | |
begin | |
if p.description.match(/^.*\.\w{2,5}$/) || p.description == "apple.news" | |
new_title = title_clean(p) | |
puts p.description + " : looks like a URL, changing to #{new_title} and updating" | |
pinboard.add(:url => p.href, :description => new_title) | |
else | |
puts p.description + " : OKAY" | |
end | |
sleep 0.5 | |
rescue Exception => e | |
puts "Had an error: #{e}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment