Instantly share code, notes, and snippets.

Embed
What would you like to do?
dofile("utils/http.lua")
dofile("utils/json.lua")
search = function(query)
local url = "http://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch=".. http.encode(query);
local headers = {
{
"User-Agent",
"AnySearch"
}
}
local r = http.get(url,headers)
local j = json.decode(r)
local results = j.query.search
local resp = {}
for k,v in pairs(results) do
local item = {
title = v.title,
description = v.title,
url = "http://en.wikipedia.org/wiki/".. v.title
}
table.insert(resp,item)
end
return resp;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment