Created
July 12, 2013 20:33
-
-
Save dhoss/5987596 to your computer and use it in GitHub Desktop.
ruby validate-links.rb /mnt/hgfs/daustin/work/linkQA.csv validate-links.rb:6:in `<main>': undefined local variable or method `hit_links' for main:Object (NameError)
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
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'csv' | |
write_to_file(hit_links) | |
def read_file | |
file = File.open(ARGV[0]).read | |
return file | |
end | |
def hit_links | |
responses = [] | |
urls = read_file | |
urls.each_line {|l| | |
url = URI.parse(l) | |
req = Net::HTTP.new(url.host, url.port) | |
res = req.get(url.path) | |
responses.push({ url => l, status => res.code}) | |
} | |
return responses | |
end | |
def write_to_csv(responses) | |
CSV.open('results.csv', 'wb') {|csv| | |
responses.each {|k,v| | |
csv << [k, v] | |
} | |
} | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment