Skip to content

Instantly share code, notes, and snippets.

@128keaton
Last active September 6, 2018 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 128keaton/b7f919ee74d9bb85959ac7fc76f75957 to your computer and use it in GitHub Desktop.
Save 128keaton/b7f919ee74d9bb85959ac7fc76f75957 to your computer and use it in GitHub Desktop.
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