Last active
September 6, 2018 00:42
-
-
Save 128keaton/b7f919ee74d9bb85959ac7fc76f75957 to your computer and use it in GitHub Desktop.
Creates a Wayback machine entry for URL
This file contains 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
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