Skip to content

Instantly share code, notes, and snippets.

@diogok
Created September 20, 2009 17:18
Show Gist options
  • Save diogok/189851 to your computer and use it in GitHub Desktop.
Save diogok/189851 to your computer and use it in GitHub Desktop.
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