Skip to content

Instantly share code, notes, and snippets.

@minikomi

minikomi/hn.lua Secret

Created November 2, 2012 10:47
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save minikomi/e449457ff64cf4bccc44 to your computer and use it in GitHub Desktop.
hn
newsurl = "http://news.ycombinator.com"
jsonp = request.query["callback"]
req = http.request({
url =newsurl,
method="GET"
})
contents = req.content
ids = {}
rank = 1
for link, title, id, points, user, comments in string.gfind(contents, "<td class=\"title\"><a href=\"(.-)\">(.-)</a><span class=\"comhead\"> %(.-%) </span></td></tr><tr><td colspan=2></td><td class=\"subtext\"><span id=score_(%d+)>(%d+).-user%?id=(.-)\".-(%d-) comments") do
table.insert(ids,{rank = rank, link = link, title = title, id = id, points = points, user = user, comments = comments})
rank = rank + 1
end
if jsonp then
return jsonp.."("..json.stringify({data = ids})..")"
else
return json.stringify({data = ids})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment