|
|
@ -7,7 +7,7 @@ local DEBUG = require("dbg")
|
|
|
|
--]]
|
|
|
|
--]]
|
|
|
|
|
|
|
|
|
|
|
|
local Wikipedia = {
|
|
|
|
local Wikipedia = {
|
|
|
|
wiki_server = "http://%s.wikipedia.org",
|
|
|
|
wiki_server = "https://%s.wikipedia.org",
|
|
|
|
wiki_path = "/w/api.php",
|
|
|
|
wiki_path = "/w/api.php",
|
|
|
|
wiki_params = {
|
|
|
|
wiki_params = {
|
|
|
|
action = "query",
|
|
|
|
action = "query",
|
|
|
@ -59,8 +59,13 @@ function Wikipedia:loadPage(text, lang, intro, plain)
|
|
|
|
error("Network is unreachable")
|
|
|
|
error("Network is unreachable")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if status ~= "HTTP/1.1 200 OK" then
|
|
|
|
|
|
|
|
DEBUG("HTTP status not okay:", status)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local content = table.concat(sink)
|
|
|
|
local content = table.concat(sink)
|
|
|
|
if content ~= "" then
|
|
|
|
if content ~= "" and string.sub(content, 1,1) == "{" then
|
|
|
|
local ok, result = pcall(JSON.decode, content)
|
|
|
|
local ok, result = pcall(JSON.decode, content)
|
|
|
|
if ok and result then
|
|
|
|
if ok and result then
|
|
|
|
DEBUG("wiki result", result)
|
|
|
|
DEBUG("wiki result", result)
|
|
|
@ -68,6 +73,8 @@ function Wikipedia:loadPage(text, lang, intro, plain)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
DEBUG("error:", result)
|
|
|
|
DEBUG("error:", result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
DEBUG("not JSON:", content)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|