parse.lua

changeset 2
5c9d6eba65bc
parent 0
0e2b5dc7ae34
child 3
5b24d66365ec
equal deleted inserted replaced
1:102ae45e5b96 2:5c9d6eba65bc
1 local http = require "socket.http" 1 local http = require "socket.http"
2 local have_https, https = pcall(require,"https"); 2 local have_https, https = pcall(require,"https");
3 local csv = require "csv" 3 local csv = require "csv"
4 4
5 for line in io.lines("gsoc10.csv") do 5 for line in io.lines(arg[1] or "gsoc12.csv") do
6 local project = {}; 6 local project = {};
7 csv.read_record(line, function (v) project[#project+1] = v; end); 7 csv.read_record(line, function (v) project[#project+1] = v; end);
8 local url = project[5]:match("https?://[^\"]+"); 8 -- FIXME: The original code doesn't work this year,
9 -- I think csv.lua doesn't handle quoted values
10 -- (ie. the 'Tags' column) properly.
11 --local url = project[5]:match("https?://[^\"]+");
12 local url = line:match(",([^,]+)$");
9 if url and url:match("^http"..(have_https and "s?" or "")..":") then 13 if url and url:match("^http"..(have_https and "s?" or "")..":") then
10 local data, err = http.request(url); 14 local data, err = http.request(url);
11 if not data then 15 if not data then
12 print("[FAIL] "..project[2]..": "..tostring(err)); 16 print("[FAIL] "..project[2]..": "..tostring(err));
13 elseif data:match("[%W%p][Ll][Uu][Aa][%W%p]") then 17 elseif data:match("[%W%p][Ll][Uu][Aa][%W%p]") then

mercurial