parse.lua

Tue, 03 Mar 2015 12:10:18 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 03 Mar 2015 12:10:18 +0000
changeset 7
95ab32c0a1ff
parent 6
39716bd98da1
permissions
-rw-r--r--

URL is now column 4

local http = require "socket.http"
local have_https, https = pcall(require,"https");
if not have_https then
	have_https, https = pcall(require,"ssl.https");
end
local csv = require "csv"

for line in io.lines(arg[1] or "gsoc15.csv") do
	local project = {};
	csv.read_record(line, function (v) project[#project+1] = v; end);
	local url = project[4] and project[4]:match("https?://[^\"]+");
	if url and url:match("^http"..(have_https and "s?" or "")..":") then
		local data, err = http.request(url);
		if not data then
			print("[FAIL] "..project[2]..": "..tostring(err));
		elseif data:match("[%W%p][Ll][Uu][Aa][%W%p]") then
			print(project[2]..": "..url);
		end
	elseif project[2] ~= "Name" then
		print("[FAIL] "..project[2]..": Couldn't fetch URL ("..(url or "couldn't find one")..")");
	end
end

mercurial