diogok (owner)

Revisions

gist: 189851 Download_button fork
public
Public Clone URL: git://gist.github.com/189851.git
Embed All Files: show embed
Lua #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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