View Single Post
Old 01-17-2009, 05:40 AM   #4
hansel
JSR FFD2
hansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheese
 
hansel's Avatar
 
Posts: 305
Karma: 1045
Join Date: Aug 2008
Location: Rotterdam, Netherlands, Europe, Sol 3
Device: iliad
Quote:
Originally Posted by Napoleon View Post
BTW, when you say it can do network stuff, what do you mean exactly?
I've been thinking about writing something in python to parse a pdf's doi (for scientific articles) and automagically download the corresponding reference in bibtex format in order to have a well organized paper database and also to create the manifest file accordingly (title, author, journal & year). Do you think it is possible with this release of lua?.
The basic network module has all the basic network functions for tcp/udp: you can connect to hosts on the internet and talk to them. The higher level functions allow you to download files over http or ftp in a few lines of code. There are also helpers to manage MIME, URLS, etc. The docs are here: http://www.tecgraf.puc-rio.br/~diego...roduction.html

Here is how you would fetch a page:

Code:
local http = require("socket.http")

b, c = http.request("http://www.google.com/search?q=lua+iliad")

file = io.open('/tmp/page.html', 'wb')
file:write(b)   -- b is the content
file:close()

print('status= ', c)    -- 200=ok, 404=not found...
I do not know what 'pdf's doi' means... Lua has less libraries than perl or python, but it has all the basic stuff. Handling text (regexp and all the expected string functions are there). I've had no problems with the xml parser to read the Iliad registry...

Last edited by hansel; 01-17-2009 at 06:06 AM. Reason: added small example
hansel is offline   Reply With Quote