Skip to content

Instantly share code, notes, and snippets.

@sburlot
Created October 9, 2013 23:10
Show Gist options
  • Save sburlot/6910129 to your computer and use it in GitHub Desktop.
Save sburlot/6910129 to your computer and use it in GitHub Desktop.
This ruby script fetches all articles from an issue of the excellent objc.io periodical and send them to Instapaper. This script should be automated so it runs automatically when a new issue is available. Perhaps parsing the RSS?
#!/usr/local/bin/ruby
# fetches the content of an objc.io issue and send it to Instapaper
# Stephan Burlot, Coriolis Technologies, http://www.coriolis.ch
# First version Oct 10, 2013
# ruby was installed via homebrew, so the path to ruby is /usr/local/bin
# you may need to change it to the actual path of your ruby installation.
require 'nokogiri'
require 'open-uri'
require 'openssl'
# this is the issue number
issue = 5
# set these to your username and your password
user = "username"
password = "password"
# fetch the editorial page
doc = Nokogiri::HTML(open('http://www.objc.io/issue-' + issue.to_s + '/editorial.html'))
# look for the content's urls
doc.xpath('//div[@class="issue-cross-links"]').each do | section |
begin
section.xpath('.//a[@href]').each do | link |
puts "Found article: " + link.content.to_s + " (" + link['href'].to_s + ")"
# set a custom title for the article
title = 'objc.io #' + issue.to_s + ' - ' + link.content.to_s
url = 'https://www.instapaper.com/api/add?title' + title + \
"&url=http://objc.io" + link['href'].to_s
#puts "url : " + url
begin
instapaper = open(URI::encode(url), {
:http_basic_authentication=>[user, password],
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE})
# catch errors
rescue OpenURI::HTTPError => status_code
the_status = status_code.io.status[0]
# status_code.message is the numeric code and text in a string
puts "Instapaper returned a bad status code: #{status_code.message}"
exit
end
end
rescue NoMethodError
puts "issue-cross-links not found"
exit
end
end
puts "End"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment