Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Hot Topic (More than 10 Replies) [Solved] Read value from Internet (Read 1593 times)
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
[Solved] Read value from Internet
Sep 27th, 2007 at 6:58pm
Print Post Print Post  
Can someone please provide example of how I can read value from a file on Internet and respond to content?  I want Sesame to check value on  line in text file on Internet web site.  If value =a then make folder and  create text file with copy of value.  If value = b then go to folder and delete file name b.txt

Text file on Internet would be set up lke INI file, so each customer's copy of Sesame reads separate section for them only.  Customer123 reads line for Customer 123 only, and Customer 234 reads line for Customer 234.  That means only one file needs to be on Internet for maintenance, but Sesame program can be wrtten to always look up the same file, just a different section for each customer. So each customer can react differently based on value for them.

So I need to be able to download INI file from internet site and use a command like ReadINI, Section CustomerID, to get the value as a variable.
« Last Edit: Oct 4th, 2007 at 12:24am by Hammer »  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Read value from Internet
Reply #1 - Sep 27th, 2007 at 8:28pm
Print Post Print Post  
I think that you could use @HTTPGetHTML along with File I/O

Make a text file like INI you described something like this:
----------------
Customer123
Cust123value
----------------
Customer234
Cust234value
----------------
Customer 345
Cust345value
----------------

Use HTTPGetHTML to read the text file to a variable

Then you could use FileI/O commands to open the file, step through each line of the INI file, ignoring all lines until you see the Customer ID, then keep the next line as a variable for that customer. 



  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Read value from Internet
Reply #2 - Sep 28th, 2007 at 7:04pm
Print Post Print Post  
Since it is a text file and it's your server (so you know the passwords), you can also use @Ftp().
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Read value from Internet
Reply #3 - Sep 29th, 2007 at 1:22am
Print Post Print Post  
Good idea for ftp.  But, as usual, I have a question:
I didn't see where the server was theirs, it mentioned getting file from Internet, but what is the difference?  Couldn't ftp also be used on the Internet?  Or you suggesting cannot use ftp on Internet because may not know the password?




====================
If this is true: Quote:
The plural of anecdote is not data.

Then this must also be true? Quote:
The plural of anecdote IS "ecdotes"
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Read value from Internet
Reply #4 - Sep 29th, 2007 at 1:27am
Print Post Print Post  
Bob_Hansen wrote on Sep 29th, 2007 at 1:22am:
Good idea for ftp.  But, as usual, I have a question:
I didn't see where the server was theirs, it mentioned getting file from Internet, but what is the difference?  Couldn't ftp also be used on the Internet?  Or you suggesting cannot use ftp on Internet because may not know the password?

By "their" server, I mean one where they have account passwords and can upload files. If they can put the file onto the Internet, they are probably using FTP to do so. I'm assuming they can therefore also get it off the Internet using FTP.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Read value from Internet
Reply #5 - Oct 2nd, 2007 at 6:13pm
Print Post Print Post  
Thank you to everyone for your ideas.  We don have our own server but we pay for annual web hosting.  We use FrontPage to put pages on the web site.  We do not use FTP.  I hope that this week i can try out using the suggestion to use @HTTPGetHTML command.  This sounds like it will be a good answer.
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Read value from Internet
Reply #6 - Oct 2nd, 2007 at 6:37pm
Print Post Print Post  
obfusc88 wrote on Oct 2nd, 2007 at 6:13pm:
Thank you to everyone for your ideas.  We don have our own server but we pay for annual web hosting.  We use FrontPage to put pages on the web site.  We do not use FTP.  I hope that this week i can try out using the suggestion to use @HTTPGetHTML command.  This sounds like it will be a good answer.


FYI: FrontPage is a shell around FTP. The login and password you gave to FrontPage should also work for FTP.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Read value from Internet
Reply #7 - Oct 3rd, 2007 at 6:23pm
Print Post Print Post  
I tried the exact lines that Bob Hansen suggested.  I made a text file and put it on our web site.  Then I wrote a small script to test out the HTTP command.  But when I get the result it has a HTML carriage return showing at the end of each line like this
----------------<cr>
Customer123<cr>
Cust123value<cr>
----------------<cr>
Customer234<cr>
Cust234value<cr>
----------------<cr>
Customer 345<cr>
Cust345value<cr>
----------------<cr>

So I tried to remove the <cr> but it stays there.  I tried just ro remove "cr" without the tags but it stays there.  But I can replace other characters like the dashes.  How can I get rid of the <cr> at the end of the lines.  If I look at the last three characters on the right I see the last two characters and a apace character.  So that space character must be what is making the <cr>?  If I look at the source page for that text page on the web there is no <cr> tags showing there.  Here is the simple program i am testing with:


var vValuePage as String

vValuePage = @HTTPGetHTML("www.mywebsite.com","/TestValues.txt","",80)

WriteLn("Original value is here: " + @NL() + vValuePage + @NL() )

vValuePage = @Replace(vValuePage,"-", "=")   //Works
vValuePage = @Replace(vValuePage,"<cr>", "")   //bad
vValuePage = @Replace(vValuePage,"cr", "")   //bad

WriteLn("Modified value is here: " + @NL() + vValuePage )
WriteLn("Last three chars are: " + @Right(vValuePage,3) )

  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Read value from Internet
Reply #8 - Oct 3rd, 2007 at 6:48pm
Print Post Print Post  
Try to use the replace with @Chr(13) which is the CR keycode.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Read value from Internet
Reply #9 - Oct 3rd, 2007 at 7:35pm
Print Post Print Post  
Using @CHR(13) worked perfectly.  I had also tried using @NL() but that did not work.  Thank you to Ray The Reapre.  Now I am trying to read the file with no <cr> tags but cannot get this correct.  This is the code I am tyring to debug now:
Quote:
/*  This button downloads a page from the internet.
File is INI file structure like this:
[Customer123]
Cust123value

[Customer234]
Cust234value

[Customer345]
Cust345value

Routine should look for [ThisCustomer] and get the next value.

*/

var vValuePage as String
var vFileHandle as Int
var vContent as String

// Get file from Internet
vValuePage = @HTTPGetHTML("www.myweb.com","/TestValues.txt","",80)

// Remove trailing <cr> tags
vValuePage = @Replace(vValuePage,@Chr(13), "")

// Read file to find first line of INI Group for this customer #234
//Save results as a file, then open and read lines

vFileHandle = fileOpen("tempfile.txt")
If vFileHandle >= 0 Then
      {
       FileWrite(vFileHandle(vValuePage)
     vFileSize = fileSize(vFileHandle)
     fileSeek(vFileHandle, 0)
     While(vContent <> "[Customer234]"
             {
           WriteLn("File Position: " + @Str(filePos(vFileHandle)))
           fileReadLn(vFileHandle, vContent)
           WriteLn(vContent)
           }
     fileReadLn(vFileHandle, vContent)
     WriteLn("Customer value = " + vContent)
       fileClose(vFileHandle)
     }
       Else
       {
     WriteLn("Open failed: " + @Str(vFileHandle))
     }

OK so i finally learned how to make the special area for the program code on here.  But the peoblem I am getting is telling me that it expects a } at position 49 on the line with While....  That line does not have that many characters.  And I have counted and only have three { and three }  .Why does it need another one?  I will be removing WriteLn but usingnow to troubleshoot.
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Read value from Internet
Reply #10 - Oct 3rd, 2007 at 7:41pm
Print Post Print Post  
obfusc88 wrote on Oct 3rd, 2007 at 7:35pm:
OK so i finally learned how to make the special area for the program code on here.  But the peoblem I am getting is telling me that it expects a } at position 49 on the line with While....  That line does not have that many characters.  And I have counted and only have three { and three }  .Why does it need another one?  I will be removing WriteLn but usingnow to troubleshoot.


1. I don't see you actually writing anything out to tempfile.txt.

2. If you already have it in a string variable, why write it to a file and read it back in.? Just parse the value in the string variable. Replace your Chr(13) with a ^ or something else you can Split on.

3. You are missing a close parenthesis on this line:
While(vContent <> "[Customer234]"
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Read value from Internet
Reply #11 - Oct 3rd, 2007 at 7:45pm
Print Post Print Post  
Is there something missing?  You can't read the temp file because you did not copy the variable into that file.  Right now it is empty.  You may also be able to just separate the  lines vs. trying to FileRead each line.


Edited:
Looks like Erika saw the same thing but beat me to it.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Read value from Internet
Reply #12 - Oct 3rd, 2007 at 7:52pm
Print Post Print Post  
I did see that one line was missing.  I was missing the FileWrite line but added it back in.  It got lsot during cut and pasting.  OK, good you found the missing ), I was looking for { } not for ().  But now you are saying not to remove the <cr> or should I still replace the @CHR(13) and replace @NL() with  ^ ?  I will run first with the missing ) and see if that works for me.  Thanks yuo for the very quick help.
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Read value from Internet
Reply #13 - Oct 3rd, 2007 at 8:13pm
Print Post Print Post  
Rather than parsing it out by hand you could also use the StringArray commands.

For Example if each line is separated by a Newline then the code below will get you the line that appears after the line that has [Customer234] on it.

Code
Select All
SetStringArraySeparator(@NewLine())
vPos = @FindStringArray(vIncomingString, "[Customer234]")
Writeln(@AccessStringArray(vIncomingString, vPos + 1))
RestoreStringArraySeparator() 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Read value from Internet
Reply #14 - Oct 3rd, 2007 at 9:13pm
Print Post Print Post  
It looks like the missing ) was the final answer.  Here is the final programming to get the value: Quote:
/*  This button downloads a page from the internet.
File is INI file structure like this:
[Customer123]
Cust123value

[Customer234]
Cust234value

[Customer345]
Cust345value

Routine should look for [ThisCustomer] and get the next value.
-----------------
*/

var vCustID as String
var vValuePage as String
var vFileHandle as Int
var vContent as String

vCustID = "[Customer234]"      

// Get file from Internet
vValuePage = @HTTPGetHTML("www.mywebsite.com","/TestValues.txt","",80)

// Remove trailing <cr> tags
vValuePage = @Replace(vValuePage,@Chr(13), "")

// Read file to find first line of INI Group
//Save results as a file, then open and read lines

If FileExists("tempfile.txt") Then {
     FileDelete("tempfile.txt")
     }

vFileHandle = FileOpen("tempfile.txt")
FileWrite(vFileHandle,vValuePage)

//  Value will be the first line after the line with [vCustID]
//  Could put inside loop for total file size to force an end if no match found
If vFileHandle >= 0 Then {
     FileSeek(vFileHandle, 0)
     While(vContent <> vCustID) {
           FileReadLn(vFileHandle, vContent)
           }
     FileReadLn(vFileHandle, vContent)
     WriteLn("The value for " + vCustID + "is: " + vContent)
     FileClose(vFileHandle)
     FileDelete("tempfile.txt")
     } Else {
     WriteLn("Could not get values from Internet")
     }


//Can now make decisions based on value of vContent. 

And now I see another answer from Ray the Reaper that looks a lot easier.  Only 4 lince of programmming and no files to open/close/delete,  And no loop that could run forever if match not found.  I think I will use that one instead of this one.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print