Skip to content

Instantly share code, notes, and snippets.

@heliostatic
Created September 8, 2009 22:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save heliostatic/183288 to your computer and use it in GitHub Desktop.
Save heliostatic/183288 to your computer and use it in GitHub Desktop.
Check and email your recent, unread links on Pinboard.in
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'mechanize'
require 'chronic'
require 'tlsmail'
require 'time'
agent = WWW::Mechanize.new
# Logging in to pinboard
page = agent.get('http://pinboard.in')
login_form = page.form('login')
login_form.username = 'USERNAME'
login_form.password = 'PASSWORD'
page = agent.submit(login_form)
# Going to the unread links page
doc = agent.click page.link_with(:text => 'unread')
new_bookmarks = []
# Getting the list of unread links
bookmarks = doc.search('div.bookmark')
bookmarks.each do |bookmark|
link_title = bookmark.search('a.bookmark_title').first.content
link_address = bookmark.search('a.bookmark_title').first.attributes['href'].to_s.sub(/^.*url=/, '')
link_time = bookmark.search('.when').first.content
new_bookmarks << {:title => link_title, :address => link_address, :time => link_time} if Chronic.parse(link_time) > Chronic.parse('yesterday')
end
links = ""
new_bookmarks.each do |bookmark|
links << "Link: " + bookmark[:title] + "\nAddress: " + bookmark[:address] + "\n\n"
end
# Create and send an email with the new links via gmail
content = <<EOF
From: from@gmail.com
To: to@gmail.com
Subject: Unread links for #{Time.now.strftime("%A %B %d, %Y")}
Date: #{Time.now.rfc2822}
Here are your new links for #{Time.now.strftime("%A %B %d, %Y")}:
#{links}
EOF
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
Net::SMTP.start('smtp.gmail.com', 587, 'gmail.com', 'FROM@gmail.com', 'PASSWORD', :login) do |smtp|
smtp.send_message(content, 'FROM@gmail.com', 'TO@gmail.com')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment