parse.lua

Sat, 31 Mar 2012 22:13:32 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 31 Mar 2012 22:13:32 +0100
changeset 2
5c9d6eba65bc
parent 0
0e2b5dc7ae34
child 3
5b24d66365ec
permissions
-rw-r--r--

parse.lua: Update for gsoc12.csv, and *hack* the code to work with the new format

0
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local http = require "socket.http"
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local have_https, https = pcall(require,"https");
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local csv = require "csv"
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
2
5c9d6eba65bc parse.lua: Update for gsoc12.csv, and *hack* the code to work with the new format
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
5 for line in io.lines(arg[1] or "gsoc12.csv") do
0
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local project = {};
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 csv.read_record(line, function (v) project[#project+1] = v; end);
2
5c9d6eba65bc parse.lua: Update for gsoc12.csv, and *hack* the code to work with the new format
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
8 -- FIXME: The original code doesn't work this year,
5c9d6eba65bc parse.lua: Update for gsoc12.csv, and *hack* the code to work with the new format
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
9 -- I think csv.lua doesn't handle quoted values
5c9d6eba65bc parse.lua: Update for gsoc12.csv, and *hack* the code to work with the new format
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
10 -- (ie. the 'Tags' column) properly.
5c9d6eba65bc parse.lua: Update for gsoc12.csv, and *hack* the code to work with the new format
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
11 --local url = project[5]:match("https?://[^\"]+");
5c9d6eba65bc parse.lua: Update for gsoc12.csv, and *hack* the code to work with the new format
Matthew Wild <mwild1@gmail.com>
parents: 0
diff changeset
12 local url = line:match(",([^,]+)$");
0
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 if url and url:match("^http"..(have_https and "s?" or "")..":") then
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local data, err = http.request(url);
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 if not data then
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 print("[FAIL] "..project[2]..": "..tostring(err));
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 elseif data:match("[%W%p][Ll][Uu][Aa][%W%p]") then
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 print(project[2]..": "..url);
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 end
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 elseif project[2] ~= "Name" then
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 print("[FAIL] "..project[2]..": Couldn't fetch URL ("..(url or "couldn't find one")..")");
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 end

mercurial