PDA

View Full Version : Retreive Internet content



Clement
April 13th, 2006, 03:54 PM
Hello all,

I am new to this great Grider script.

I like to know if I can program it (using LUA) to get an Internet page and analize it's content, extract some data from it and have Grider start some actions based on the variables contained in that page.


Best regards,
Clement

Rob H
April 13th, 2006, 04:14 PM
It's certainly all possible, yes.

You can use win.URLDownloadToMemory() to fetch the page as a string.

After that it's pretty much up to you, but we'll help if you have any specific questions.

Clement
April 14th, 2006, 02:25 AM
Great. This is good news for me.

Thank you very much for your replay.

I'll try to get myself familiar with the scripts and ask if there is no chance for me to figure out things.

However, the great news is this is doabla.

Thank you again,
Clement

Rob H
April 14th, 2006, 05:25 AM
You may want to say which web pages you are trying to process. Someone may already have either done it or made a start on it.

Clement
April 14th, 2006, 06:58 AM
Thank you Rob.

In fact I want to use a custom system as explained bewllow
BUT if anything like that (Internet content retrival and hanling) is already done it will be very helpful for me to point me there so I can see how the Girder-Lua scripting is handling for this purpose.


Basically, I want to point Girder to get information from some custom pages I will make and have Girder (and HAL) react to it.

Those pages will contrain personal intersts informations like:

1) If I have any new order to handle on my online stores.

2) Informations about my hosting server

3) Some alerts based on the currency rates on my country (Romania)

To simplify the LUA script I will be able to put on the Internet pages only a small amount of info like:

HAL flag name and HAL flag status
And after that I want to have Girder change the HAL flag accordingly within the computer.

HAL - stands for Home Automated Living system ( www.automatedliving.com )

Thank you again,
Clement

Rob H
April 14th, 2006, 07:24 AM
It would certainly be simpler if you have control over the page format.

Even better would be if HAL generated the pages using XML and an XSL transform then you could parse the XML directly, but I don't know if that's possible.

Clement
April 14th, 2006, 07:44 AM
I thing I wasn't so clear.

HAL is on the same home networked computer.

The web pages are generate on a remote Internet server (using PHP) and I need that pages to be readed BY Girder and pass an action to HAL.

Please let me know if I wasn't clear this time, too .

Clement
April 14th, 2006, 10:53 AM
As you encouraged me I'll start with my questions :)


I created a scripting action placing only the following code:


page = win.URLDownloadToMemory("http://www.mydomain.com/test.php");
print(page)

When I first tested the action it seems to be ok and the page content is displayed in the Lua console.

However, I noticed a problem when I changed something into the test.php page.

Even if the test.php was changed on the hosting server each time I test the Lua script I get the old content of the file.

I noticed that if I open the Internet Explorer and refresh that test.php file then the Lua script will display the new page content.
It seems like Lua get the page content from the IE cache and not from the page itself.

Anything I am missing ?


Thank you,
Clement

Rob H
April 14th, 2006, 11:03 AM
Okay, it looks as though win.URLDownloadToMemory is getting the image from the cache.

Try this instead :-


require('socket.http') ;

local page, err = socket.http.request(http://www.mydomain.com/test.php")

If the function succeeds then err should equal 200 and page will contain the text of the page.

Clement
April 14th, 2006, 12:58 PM
Great! It works. Thank you very much.

Now, I have another challenge :)

On the simpliest scenario, the internet page content hase only 1 word (string) that I want to be passed as a parameter to another program on the Girder PC.

For example, the page content is: GOOD

Now, within Lua script I have the Lua variable page = "GOOD"

Now I want to start a program.exe parameter,GOOD

It seems I can't find a "run program" function in the Lua documentation.

Is anything like that there and I don't see it?

Thankl you again,
Clement

Rob H
April 14th, 2006, 03:12 PM
Take a look at win.ShellExecuteEx in the help

Clement
April 14th, 2006, 04:12 PM
Great again!

You saved me a lot of time and now I am very close to have my first 2 custom uses of Girder.
This assured that my trial version will become a Pro version for sure! :)

I'll place here my custom uses for ones interested on how Girder can be used.

On short the uses are:

1) I have a Microsoft Fingerprints Reader on the front door that me and my wife (or relatives) touch when enter to our home.

The fingerprint reader software (named GrFinger) identify the person and simulate a keystoke string with a person ID.

Now, using Girder, that keystoke string is captured and I can start anything I want based on the identity.
In my personal installation this will change an occupancy flag in HAL and have HAL handle the House Modes and other occupancy (arrival/departures) macros.

2) Another use of Girder will be in the Internet content field.
I'll have Girder check some certain pages on my sites and find if I have any order on my online stores.
Based on that information, the Girder will start diferent actions.

In my personal installation, Girder will inform HAL about the online orders and hav HAL making announcements in the room I am at that moment and display on the TV screen some usefull informations about these orders.

I plan another uses for Girder-HAL couple but I only learned 2 basic Lua functions at this moment (thanks to Rob's help )


Best regards,
Clement

Rob H
April 14th, 2006, 06:18 PM
Welcome aboard.