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

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");
4
0dc2ccd703e3 Some packages have ssl.https...
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
3 if not have_https then
0dc2ccd703e3 Some packages have ssl.https...
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
4 have_https, https = pcall(require,"ssl.https");
0dc2ccd703e3 Some packages have ssl.https...
Matthew Wild <mwild1@gmail.com>
parents: 3
diff changeset
5 end
0
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local csv = require "csv"
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
6
39716bd98da1 Update default to gsoc15.csv
Matthew Wild <mwild1@gmail.com>
parents: 4
diff changeset
8 for line in io.lines(arg[1] or "gsoc15.csv") do
0
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local project = {};
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 csv.read_record(line, function (v) project[#project+1] = v; end);
7
95ab32c0a1ff URL is now column 4
Matthew Wild <mwild1@gmail.com>
parents: 6
diff changeset
11 local url = project[4] and project[4]:match("https?://[^\"]+");
0
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 if url and url:match("^http"..(have_https and "s?" or "")..":") then
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local data, err = http.request(url);
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 if not data then
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 print("[FAIL] "..project[2]..": "..tostring(err));
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 elseif data:match("[%W%p][Ll][Uu][Aa][%W%p]") then
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 print(project[2]..": "..url);
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 end
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 elseif project[2] ~= "Name" then
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 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
21 end
0e2b5dc7ae34 Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end

mercurial