Skip to content

Instantly share code, notes, and snippets.

@128keaton

128keaton/archiver.rb

Last active Sep 6, 2018
Embed
What would you like to do?
Creates a Wayback machine entry for URL
require 'net/https'
require 'uri'
class WebArchiver
def self.archive(url)
url = URI.parse("https://web.archive.org/save/#{url}")
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port, :use_ssl => true) {|http|
http.request(req)
}
if res.code == '200'
puts 'Archived or already archived'
elsif res.code == '502'
puts 'Page unable to be archived'
else
puts res.code
puts res.body
end
end
if ARGV[0]
url = URI.parse(ARGV[0])
self.archive(url)
else
puts 'Invalid URL'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment