mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
#131652 04/10/05 02:44 PM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
yeah tus why i said to remove it.. i didnt know he wanted to use the scan switch for that purpose


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
#131653 06/10/05 08:49 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
The code works fine, however, I was wondering if a few extras could be implemented.
1) Allow the date entries to be entered using one of the following:
A) a single number, which would default to an entry of that day in the current month, returning an error if that date doesn't exist
B) mmm dd, which would default to that date in the current year
C) allow for mmm dd yy, or mmm dd yyyyy, or m/d/yy, or m/d/yyyy

I already have a line so that the date will default to the current date if there is no entry, but if it's not one of the above mentioned formats, then I should get an error message

2) could someone also code a phone number look up?
The site I'd use would be http://findaperson.canada411.ca/ with the city & province being preset. The name is supplied in the dialog, and will be in the format of Surname, Given Name. Address is also in the dialog.

I understand that this second item will require usage of sockets, and I tried to find a very basic socket tutorial in order to try to do it myself, but all of the tutorials I found required you to already have a basic knowledge of sockets...which at the moment is more than I have.
If the socket code could also include detailed documentation as to what's happening where and why, it would be appreciated as I prefer to understand a code, even if it's longer than necessary, rather than having a short code that I don't understand.

#131654 10/10/05 09:39 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
OK, I've got the date configuration working the way I want, but I'm still having trouble understanding sockets in order to get the phone number information from the website. I realize that scripts aren't usually written for a one time usage, and that I could look up the phone numbers one at a time, but I've got nearly 500 numbers to look up, so I was thinking that using a script, even just once, would save a lot of time.

#131655 18/10/05 05:54 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Well, I've had a bit of luck with this, and here's the code that I've currently got. Problem is, it's not returning the proper value, and I'm not sure why. There isn't any error messages being generated, but I don't seem to be getting a response either.
Code:
 on *:DIALOG:Observer:sclick:7: {  
  save.data 
  var %file = $+($did($dname,5).seltext,.ini), %acct = $did($dname,7).seltext  
  did -ra $dname 9 $readini(%file,n,%acct,Name)  
  did -ra $dname 11 $readini(%file,n,%acct,Address)  
  did -ra $dname 13 $readini(%file,n,%acct,Apt)  
  if !$readini(%file,n,%acct,Phone) { 
    var %surname = $iif($numtok($did($dname,9),44) > 1,$gettok($did($dname,9),1,44),$did($dname,9)) 
    var %given = $iif(%surname != $did($dname,9),$gettok($did($dname,9),2,44)) 
    .enable phone 
    find.a.person %surname $iif(%given,%given) 
  } 
  did -a $dname 15 $readini(%file,n,%acct,Phone)  
  did $iif($readini(%file,n,%acct,Active),-c,-u) $dname 17 
  did -rca $dname 18 $readini(%file,n,%acct,Billing)  
  did -rca $dname 16 $readini(%file,n,%acct,Deliveries)  
  did -ra $dname 22 $readini(%file,n,%acct,Expiry) 
  did -rca $dname 25 $gettok($readini(%file,n,%acct,Start),-1,32) 
  did -rca $dname 26 $gettok($readini(%file,n,%acct,Stop),-1,32) 
} 
#phone off 
alias find.a.person { 
  if (!$isid) { 
    set %firstname $1 
    set %lastname $2 
    sockopen findap findaperson.canada411.ca 80 
  } 
} 
on *:sockopen:findap:{ 
  sockwrite -n $sockname GET $+(/10649/search/Find_Person?firstname=,%firstname,&name=,%lastname,&city_zip=Sarnia&state_id=ON) HTTP/1.1 
  sockwrite -n $sockname Host: findaperson.canada411.ca $+ $crlf $+ $crlf 
} 
on *:sockread:findap:{ 
  if ($sockerr) { 
    echo -a some error occored oh no. 
    return 
  } 
  else { 
    var %nc 
    sockread %nc 
    if $wildtok(%nc,$+(*,%lastname,*),0,95) { 
      var %fulladdress = $gettok(%nc,5,61) 
      var %apt = $right($gettok(%fulladdress,2,37),-2) 
      var %street = $gettok($replace($gettok(%fulladdress,3-,37),20,$chr(32)),1,38) 
      var %address = $+($gettok(%fulladdress,1,37),%street) 
      if $did($dname,11) == %address && $did($dname,13) == %apt { 
        did -a $dname 15 $right($gettok($gettok(%nc,11,61),1,38),8) 
      } 
    } 
    if (%nc == </HTML>) { sockclose findap } 
  } 
} 
#phone end 
 

#131656 18/10/05 01:21 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Well, you are getting invalid data in your socket..

If I echo your variables when searching for a random name that I know is on the site:

(I put this inside your IF statement):
echo -a %fulladdress ~ %apt ~ %street ~ %address

Results:
Quote:

"regular_field" maxlength ~ ~ ~ "regular_field" maxlength
85%20Maplestone%20Ave&_RM_HTML_STREET_ESC_ ~ Maplestone ~ Ave ~ 85 Ave
~ ~ ~
10180201443947680553&sort ~ ~ ~ 10180201443947680553&sort
~ ~ ~
~ ~ ~

As you can see, this is obviously invalid data.

Try:

Code:
    if (*RM_HTML_FIRST_ESC* iswm %nc) { 
      var %fulladdress = $gettok(%nc,5,61) 
      var %apt = $right($gettok(%fulladdress,2,37),-2) 
      var %street = $gettok($replace($gettok(%fulladdress,3-,37),20,$chr(32)),1,38) 
      var %address = $+($gettok(%fulladdress,1,37),%street) 

      echo -a %fulladdress ~ %apt ~ %street ~ %address
    } 


I removed the DID information because I don't have your dialog table to test it with. Just insert that back in once you have it working on the //echo with the correct data. Is this the right data in your variables?

%fulladdress === 85%20Maplestone%20Ave&_RM_HTML_STREET_ESC_
%apt === Maplestone
%street === Ave
%address === 85 Ave


The change I did was to fix your IF... you didn't need to check for that $wildtok text as that brought up unneeded results. This brings up only one result.


Invision Support
#Invision on irc.irchighway.net
#131657 19/10/05 04:02 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Thanks for your help Riamus2. That has helped solve the problem I was having, however, one thing I didn't think of before, is what if there's more than one match on the search? How do I go about ensuring that I get the information for the correct match? For example, if I search for A. Smith in Sarnia, ON...I get 10 results...How do I ensure that the phone number is for the right A. Smith?

Sort of on the same topic, I've found that some of the people have an apartment number of 2 in my listings, yet in the directory, it's marked as 1/2. I can't seem to get the apartment number to change to match what is in the directory.

Here's the socket read section of my code as I currently have it
Code:
 on *:sockread:findap:{ 
  if ($sockerr) { 
    echo -a some error occored oh no. 
    return 
  } 
  else { 
    var %nc 
    sockread %nc 
    if (*RM_HTML_FIRST_ESC* iswm %nc) {
      var %nc = $replace(%nc,$+($chr(37),20),$chr(32))
      var %last = $gettok($gettok(%nc,4,61),1,38)
      var %first = $iif(!%firstname,$gettok($gettok(%nc,3,61),1,38),%firstname)
      var %address = $gettok($gettok(%nc,7,61),1,38)
      var %apt = $gettok(%address,-1,32)
      var %address = $gettok(%address,1,32)
      var %street = $gettok($gettok(%nc,6,61),1,38)
      var %phone = $gettok($gettok($gettok(%nc,-3,61),1,38),-1,32)
    }
    ;    if $did(Observer,13) != %apt {      did -a Observer 13 %apt    }
    if !$did(Observer,15) && %phone {      did -a Observer 15 %phone    }
    if (%nc == </HTML>) { sockclose findap } 
  } 
}
 


The line is remarked at the moment, due to the fact that it doesn't work. When I tried it, as written, it changed 2 to 21/2

#131658 19/10/05 01:02 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Use /did -ra to change a value. -a appends. You need -r to remove what is already there.

As for knowing the correct person, you would need to have some idea of what address is the correct one. You could then compare it to determine which is right. Alternatively, you could have it store the ones that have multiple addresses in a file or a hash table or wherever and then go through them manually, later. If you could give an example from your listing that has multiple listings on the website, I may be able to set it up to automatically choose the right one. If you don't want to include a real address/name, then go on there and pick some random name, like I did, that brings up multiple names and then make a "fake" part to match how it would appear in your listing so I can compare the two. If you can give a few examples, it would help out.


Invision Support
#Invision on irc.irchighway.net
#131659 20/10/05 12:00 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
The address in Number Street Name format is in $did(Observer,11). The apartment number, if applicable, is in $did(Observer,13)

I did a test run using A Smith and got 10 listings. Saving the results to a html file, then viewing that file in Notepad showed a file with 707 lines. I have edited that down so that it the following contains just the relevant information (or at least I hope I didn't remove information that was relevant and/or include irrelevant information)

I've pasted the information here as it shows in Notepad with WordWrap turned off
Quote:
<SCRIPT language=javascript1.1 type=text/javascript
xmlns:str="http://exslt.org/strings">
<!--
// SITE: Canada 411
// PAGE: PERS_RESULTS_1
oas_url = 'http://oasads.whitepages.com/RealMedia/ads/';
oas_sitepage = 'canada411.whitepages.com/RESULTS';
oas_listpos = 'Medium_Rect,Popunder,HeadingText,ResultsLink3,ResultsLink2,x50,Banner';
oas_rn = '01234567890';
oas_rns = '1234567890';
oas_rn = new String(Math.random());
oas_rns = oas_rn.substring(2,11);
oas_version = 10;
oas_query = '?'+"_RM_HTML_FIRST_ESC_=A&_RM_HTML_LAST_ESC_=Smith&_RM_HTML_ADDRESS_ESC_=341%20Mitton%20St%20S&_RM_HTML_STREET_ESC_=Mitton%20St%20S&_RM_HTML_HOUSE_ESC_=341&_RM_HTML_CITY_ESC_=Sarnia&_RM_HTML_STATE_ESC_=ON&_RM_HTML_ZIP_ESC_=N7T%203E4&_RM_HTML_PHONE_ESC_=(519)%20337-0861&CITY=Sarnia&STATE=ON";
oas_target = '_top';
function OAS_NORMAL(pos) {
document.write('<a href="' + oas_url + 'click_nx.ads/' + oas_sitepage + '/1' + oas_rns + '\@' + oas_listpos + '!' + pos + oas_query + '" target=' + oas_target + '>');
document.write('<img src="' + oas_url + 'adstream_nx.ads/' + oas_sitepage + '/1' + oas_rns + '\@' + oas_listpos + '!' + pos + oas_query + '" border=0></a>');
}
// -->
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_1','__FIRST__',"A");
swapElementText('resultlink_1','__LAST__',"Smith");
swapElementText('resultlink_1','__CITY__',"Sarnia");
swapElementText('resultlink_1','__STATE__',"ON");
swapElementText('resultlink_1','__ADDRESS_ESC__',"341%20Mitton%20St%20S");
swapElementText('resultlink_1','__FIRST_ESC__',"A");
swapElementText('resultlink_1','__LAST_ESC__',"Smith");
swapElementText('resultlink_1','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_1','__STATE_ESC__',"ON");
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_2','__FIRST__',"A");
swapElementText('resultlink_2','__LAST__',"Smith");
swapElementText('resultlink_2','__CITY__',"Sarnia");
swapElementText('resultlink_2','__STATE__',"ON");
swapElementText('resultlink_2','__ADDRESS_ESC__',"664%20Murphy%20Rd");
swapElementText('resultlink_2','__FIRST_ESC__',"A");
swapElementText('resultlink_2','__LAST_ESC__',"Smith");
swapElementText('resultlink_2','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_2','__STATE_ESC__',"ON");
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_3','__FIRST__',"A");
swapElementText('resultlink_3','__LAST__',"Smith");
swapElementText('resultlink_3','__CITY__',"Sarnia");
swapElementText('resultlink_3','__STATE__',"ON");
swapElementText('resultlink_3','__ADDRESS_ESC__',"114%20Hanna%20Cres");
swapElementText('resultlink_3','__FIRST_ESC__',"A");
swapElementText('resultlink_3','__LAST_ESC__',"Smith");
swapElementText('resultlink_3','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_3','__STATE_ESC__',"ON");
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_4','__FIRST__',"A & K");
swapElementText('resultlink_4','__LAST__',"Smith");
swapElementText('resultlink_4','__CITY__',"Sarnia");
swapElementText('resultlink_4','__STATE__',"ON");
swapElementText('resultlink_4','__ADDRESS_ESC__',"1625%20Aftoncrt");
swapElementText('resultlink_4','__FIRST_ESC__',"A%20&%20K");
swapElementText('resultlink_4','__LAST_ESC__',"Smith");
swapElementText('resultlink_4','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_4','__STATE_ESC__',"ON");
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_5','__FIRST__',"A Chris");
swapElementText('resultlink_5','__LAST__',"Smith");
swapElementText('resultlink_5','__CITY__',"Sarnia");
swapElementText('resultlink_5','__STATE__',"ON");
swapElementText('resultlink_5','__ADDRESS_ESC__',"231%20Cobden%20St");
swapElementText('resultlink_5','__FIRST_ESC__',"A%20Chris");
swapElementText('resultlink_5','__LAST_ESC__',"Smith");
swapElementText('resultlink_5','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_5','__STATE_ESC__',"ON");
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_6','__FIRST__',"A E");
swapElementText('resultlink_6','__LAST__',"Smith");
swapElementText('resultlink_6','__CITY__',"Sarnia");
swapElementText('resultlink_6','__STATE__',"ON");
swapElementText('resultlink_6','__ADDRESS_ESC__',"345%20Willowdale%20Cres");
swapElementText('resultlink_6','__FIRST_ESC__',"A%20E");
swapElementText('resultlink_6','__LAST_ESC__',"Smith");
swapElementText('resultlink_6','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_6','__STATE_ESC__',"ON");
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_7','__FIRST__',"A P");
swapElementText('resultlink_7','__LAST__',"Smith");
swapElementText('resultlink_7','__CITY__',"Sarnia");
swapElementText('resultlink_7','__STATE__',"ON");
swapElementText('resultlink_7','__ADDRESS_ESC__',"780%20Alexander%20St");
swapElementText('resultlink_7','__FIRST_ESC__',"A%20P");
swapElementText('resultlink_7','__LAST_ESC__',"Smith");
swapElementText('resultlink_7','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_7','__STATE_ESC__',"ON");
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_8','__FIRST__',"Allen W");
swapElementText('resultlink_8','__LAST__',"Smith");
swapElementText('resultlink_8','__CITY__',"Sarnia");
swapElementText('resultlink_8','__STATE__',"ON");
swapElementText('resultlink_8','__ADDRESS_ESC__',"1053%20Talfourd%20St");
swapElementText('resultlink_8','__FIRST_ESC__',"Allen%20W");
swapElementText('resultlink_8','__LAST_ESC__',"Smith");
swapElementText('resultlink_8','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_8','__STATE_ESC__',"ON");
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_9','__FIRST__',"Andy");
swapElementText('resultlink_9','__LAST__',"Smith");
swapElementText('resultlink_9','__CITY__',"Sarnia");
swapElementText('resultlink_9','__STATE__',"ON");
swapElementText('resultlink_9','__ADDRESS_ESC__',"515%20Erindale%20Crt");
swapElementText('resultlink_9','__FIRST_ESC__',"Andy");
swapElementText('resultlink_9','__LAST_ESC__',"Smith");
swapElementText('resultlink_9','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_9','__STATE_ESC__',"ON");
</SCRIPT>
<SCRIPT language=javascript type=text/javascript
xmlns:str="http://exslt.org/strings">
swapElementText('resultlink_10','__FIRST__',"Anthony");
swapElementText('resultlink_10','__LAST__',"Smith");
swapElementText('resultlink_10','__CITY__',"Sarnia");
swapElementText('resultlink_10','__STATE__',"ON");
swapElementText('resultlink_10','__ADDRESS_ESC__',"1011%20Frost%20Ave");
swapElementText('resultlink_10','__FIRST_ESC__',"Anthony");
swapElementText('resultlink_10','__LAST_ESC__',"Smith");
swapElementText('resultlink_10','__CITY_ESC__',"Sarnia");
swapElementText('resultlink_10','__STATE_ESC__',"ON");
</SCRIPT>

#131660 20/10/05 04:34 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
NOTE: You can view the source without saving it to an HTML file by right clicking in your browser and choosing "View Source". If you use something other than IE, it may be called something else, or may be located under a View menu or something similar. (IE also has it in the View menu).

Ok, let's see if I know for sure what you're trying to do...

You have a bunch of addresses in your dialog and you're trying to update them with the phone number?

If that's the case, we already have the address off the website thanks to the socket...

Put the variables for the parts of the address into the correct order and check if they equal the dialog value. If so, insert the phone number.

Something like:

Code:
if ($did(Observer,11) == %address %street) {
  did -ra Observer [color:red][Phone's ID][/color] [color:blue]%phone [/color][color:green](see below for where this comes from)[/color]
}


To get the phone variable to use above, insert this into the same place where you're setting the address variables:

Code:
var %phone = $replace($gettok($gettok(%nc,11,61),1,38),$+(%,20),$chr(32))



One other note, you probably should put your %apt changing part into that IF section, too. Otherwise, if you happen to have only one match and it's the wrong one, the apartment will be changed even when it shouldn't be. If you put it into this IF statement, then you'll only change the apartment if the rest of the address matches.


Invision Support
#Invision on irc.irchighway.net
#131661 20/10/05 04:58 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Basically, yes, that's the situation. Thanks for you help, I'll fix up the code and try it. As I think I mentioned before, I could do this one by one, but with nearly 500 entries, it would take a while.

And thanks for the note about viewing the source. I wasn't aware I could do that, so I went with a method I knew would work.

#131662 20/10/05 05:44 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I've tested this, and noted a few problems, but I'm too tired at the moment to write them up, and try to explain what it is I'm wanting versus what I'm getting, so I'll probably do that tomorrow when I get up.

#131663 20/10/05 01:13 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok, sounds good. smile


Invision Support
#Invision on irc.irchighway.net
#131664 20/10/05 11:47 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
When reading the information from the site, if there's no apartment number, then the apartment number is defaulting to the same as the house number in the address field.
Also wondered if there was a way to set it so that it doesn't look up information for people that already have all the information entered. Additonally, I was wondering if there's a way of speeding up the process of getting the information from the site. Currently I'm seeing times of between 4000 and 18000 ticks. I'm not exactly sure how long a tick is, but it was the easiest way to get a timing. I'm currently using a 1M DSL connection.

The information in the Start field (Observer,25) and the Stop field (Observer,26) always come back empty. I realize that's nothing to do with the sockets.

My full code, as it currently stands is
Code:
 alias obs {
  dialog -m Observer Observer
}
dialog Observer {
  title "Observer"
  size -1 -1 300 100
  option dbu
  button "Cancel", 1, 10 40 20 10, cancel
  button "OK", 2, 40 40 20 10, ok
  button Store New Info, 3, 10 60 50 10, default
  text "Rte", 4, 10 10 20 10
  combo 5, 30 10 30 10, edit drop
  text "Account", 6, 10 20 20 10
  combo 7, 30 20 60 10, edit drop
  text "Name", 8, 100 10 25 10
  edit "", 9, 130 10 50 10, autohs
  text "Address", 10, 100 20 25 10
  edit "", 11, 130 20 50 10, autohs
  text "Apt.", 12, 190 20 20 10
  edit "", 13, 210 20 20 10, autohs
  text "Phone", 14, 100 40 25 10
  edit "", 15, 130 40 50 10, autohs
  combo 16, 130 30 50 10, edit drop
  check "Active", 17, 190 30 30 10, left
  combo 18, 130 50 50 10, edit drop
  text "Billing", 19, 100 50 20 10
  text "Delivery", 20, 100 30 25 10
  text "Expires", 21, 190 50 25 10
  edit "", 22, 220 50 50 10, autohs
  box User Info, 1000, 95 2 180 92
  text "Start", 23, 100 60 25 8
  text "Stop", 24, 190 60 25 8
  combo 25, 130 60 50 10, edit drop
  combo 26, 220 60 50 10, edit drop
  edit "", 27, 130 70 50 10
  text "Balance", 28, 100 70 25 8
  text "Pay Date", 29, 100 80 25 8
  text "Amount", 31, 190 80 25 8
  combo 32, 130 80 50 10, edit drop
  edit "", 33, 220 80 50 10
}
on *:DIALOG:Observer:INIT:*: {
  unset %edited
  if !$lines(Observer.txt) {        echo -a 8,1ALERT!!! No routes established    }
  else {
    var %a = 1
    while %a &lt;= $lines(Observer.txt) {
      did -a $dname 5 $read(Observer.txt,t,%a)
      inc %a    
    }  
  }  
  ;  
  did -a $dname 16 Daily  
  did -a $dname 16 Sat. Only  
  did -a $dname 16 MP/LL  
  ;  
  did -a $dname 18 Office  
  did -a $dname 18 Monthly  
  did -a $dname 18 Bi-wkly  
  ;  
  did -rca $dname 25 $adate
}

on *:DIALOG:Observer:sclick:5: {  
  var %rte = $did($dname,5).seltext  
  if !$exists($+(%rte,.ini)) {    echo -a 8,1ALERT!!!4,1 You have no entries for Rte %rte    }
  else {
    var %obs.store = 1, %obs.calc = $ini($+(%rte,.ini),0)   
    while (%obs.store &lt;= %obs.calc) {
      did -a $dname 7 $ini($+(%rte,.ini),%obs.store)      
      inc %obs.store    
    }  
    if $did($dname,16).sel == 3 {      unset %collect    }
    elseif $did($dname,16).sel == 1 {
    }
  }
}
alias save.data {
  if %edited {
    var %file = $iif(!$did($dname,5).seltext,$did($dname,5),$did($dname,5).seltext)  
    .write -s $+ %file Observer.txt %file
    var %file = $+(%file,.ini),%acct = $iif(!$did($dname,7).seltext,$did($dname,7),$did($dname,7).seltext)  
    .writeini -n %file %acct Name $did($dname,9)  
    .writeini -n %file %acct Address $did($dname,11)  
    $iif(!$did($dname,13),.remini %file %acct Apt,.writeini -n %file %acct Apt $did($dname,13))
    $iif(!$did($dname,15),.remini %file %acct Phone,.writeini -n %file %acct Phone $did($dname,15))
    .writeini -n %file %acct Active $did($dname,17).state  
    .writeini -n %file %acct Billing $did($dname,18).seltext  
    .writeini -n %file %acct Deliveries $did($dname,16).seltext  
    .writeini -n %file %acct Expiry $iif($did($dname,22),$did($dname,22),$adate)  
    if $did($dname,17).edited {    did -a $dname $iif($did($dname,17).state,25,26) $adate    }
    .writeini -n %file %acct Start $didtok($dname,25,32)  
    if $didtok($dname,26,32) {        .writeini -n %file %acct Stop $didtok($dname,26,32)    }
    if $didtok($dname,32,32) {        .writeini -n %file %acct Paid $didtok($dname,32,32)    }
  }
  unset %edited
}
on *:DIALOG:Observer:sclick:7: {  
  set %ticks $ticks
  save.data
  var %file = $+($did($dname,5).seltext,.ini), %acct = $did($dname,7).seltext  
  did -ra $dname 9 $readini(%file,n,%acct,Name)  
  did -ra $dname 11 $readini(%file,n,%acct,Address)  
  did -ra $dname 13 $readini(%file,n,%acct,Apt)  
  if !$readini(%file,n,%acct,Phone) {
    var %surname = $iif($numtok($did($dname,9),44) &gt; 1,$gettok($did($dname,9),1,44),$did($dname,9))
    var %given = $iif(%surname != $did($dname,9),$gettok($did($dname,9),2,44))
    find.a.person %surname $iif(%given,%given)
  }
  did $iif($readini(%file,n,%acct,Active),-c,-u) $dname 17
  did -rca $dname 18 $readini(%file,n,%acct,Billing)  
  did -rca $dname 16 $readini(%file,n,%acct,Deliveries)  
  did -ra $dname 22 $readini(%file,n,%acct,Expiry)
  did -rca $dname 25 $gettok($readini(%file,n,%acct,Start),-1,32)
  did -rca $dname 26 $gettok($readini(%file,n,%acct,Stop),-1,32)
}
alias find.a.person { 
  if (!$isid) { 
    ;set the searchterm to be used later on when we suply the url 
    set %lastname $1 
    set %firstname $2 
    sockopen findap findaperson.canada411.ca 80 
  } 
} 
on *:sockopen:findap:{ 
  sockwrite -n $sockname GET $+(/10649/search/Find_Person?firstname=,%firstname,&amp;name=,%lastname,&amp;city_zip=Sarnia&amp;state_id=ON) HTTP/1.1 
  sockwrite -n $sockname Host: findaperson.canada411.ca $+ $crlf $+ $crlf 
} 
on *:sockread:findap:{ 
  if ($sockerr) { 
    echo -a some error occored oh no. 
    return 
  } 
  else { 
    var %nc 
    sockread %nc 
    if (*RM_HTML_FIRST_ESC* iswm %nc) {
      echo -a $calc($ticks - %ticks)
      var %nc = $replace(%nc,$+($chr(37),20),$chr(32))
      var %last = $gettok($gettok(%nc,4,61),1,38)
      var %first = $iif(!%firstname,$gettok($gettok(%nc,3,61),1,38),%firstname)
      var %address = $gettok($gettok(%nc,7,61),1,38)
      var %apt = $gettok(%address,-1,32)
      var %address = $gettok(%address,1,32)
      var %street = $gettok($gettok(%nc,6,61),1,38)
      var %phone = $gettok($gettok($gettok(%nc,-3,61),1,38),-1,32)
      if ($did(Observer,11) == %address %street) &amp;&amp; ($did(Observer,13) == %apt) {
        did -ra Observer 15 %phone
      }
      elseif ($did(Observer,11) == %address %street) {
        did -ra Observer 13 %apt
        did -ra Observer 15 %phone
      }
    }
    if (%nc == &lt;/HTML&gt;) { sockclose findap } 
  } 
  echo -a $calc($ticks - %ticks)
}
on *:DIALOG:Observer:sclick:2,3: {
  save.data
}
 

#131665 21/10/05 03:54 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok...

1) Use this to set your %apt information... the other method wouldn't work because all that it was doing was displaying the last word in %address... and %address was just the street number.
Code:
      if (*%23* iswm $gettok($gettok(%nc,5,61),1,38)) {
        var %apt = $gettok($gettok($gettok(%nc,5,61),1,38),-1,32)
      }


2) If you want to avoid looking things up, then you'd need to do a check on the name... basically: If ($did(Observer,ID) == $null || $did(Observer,ID2) == $null) { get name from site } else { don't }

(I'll let you code that... if you have questions after you try, let me know).

3) The best way to speed up sockets is to stop the socket before the end of the page. Look at the source code and find the first unique piece of code following the last data you need and then sockclose on that instead of on </html>. Depending on where your data is in the source, you could save a lot of time this way... but if your data is right near the end, it won't really make much difference. In this case, I think I'd stop with:

if (<div style="text-align:left;* iswm %nc) { sockclose findap }

It won't save a lot of time, but it will save some.

4) Just a note... the site splits the results onto multiple pages... this will cause you a LOT of problems if your correct names aren't on page 1. You may have to start another socket up to pull up page 2 and then page 3 and so on... it's rather troublesome to need to do that. And I don't see any options on the site for allowing 50 (or some other large number) names per page... it's at 10 by default.


Invision Support
#Invision on irc.irchighway.net
#131666 21/10/05 08:42 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
As you noted, there's a chance of the correct match not being on the first page, and I've also found that even if it is on the first page, if it's not the first one encountered, then my code comes up incorrect.

This works if there's only one match or if the first match is the correct one. Any suggestions as to how to handle the other possibilities?
Code:
 on *:sockread:findap:{ 
  if ($sockerr) { 
    echo -a some error occored oh no. 
    return 
  } 
  else { 
    var %nc 
    sockread %nc 
    if (*_RM_HTML_* iswm %nc) {
      var %nc = $replace(%nc,$+($chr(37),20),$chr(32)), %token = 1
      while %token &lt; $wildtok(%nc,*_RM_HTML_*,0,61) {
        var %item = $gettok($wildtok(%nc,*_RM_HTML_*,%token,61),4,95)
        var %info = $gettok($wildtok(%nc,$+(*,%item,*),1,38),-1,61)
        if (%item == Address) {
          var %address = $iif(!$did(Observer,13),$did(Observer,11),$instok($did(Observer,11),$did(Observer,13),2,32))
          if (%address == %info) {          set %correct 1        }
        }
        inc %token
      }
      var %item = $gettok($wildtok(%nc,*_RM_HTML_*,%token,61),4,95)
      var %info = $gettok($wildtok(%nc,$+(*,%item,*),1,38),-1,61)
      if %correct {
        did -ra Observer 15 %info
        unset %correct
      }
      else {        echo 4 -a %item %info      }
    }
    if (&lt;LINK* iswm %nc) {      sockclose findap    }
  } 
}
 

#131667 21/10/05 01:42 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok, the problem is that you are really looking in the wrong place for address information. I took a look at the source a bit more...

Try this instead of you if (*_RM_HTML_* iswm %nc) { section that you have now:

Code:
    if (&lt;div class="textb"* iswm %nc) {
      var %last = $remove($gettok(%nc,-1,62),$chr(44))
      sockread %nc
      var %first = $gettok($gettok(%nc,-1,9),1,60)
    }
    if (&lt;div class="text"&gt;* iswm %nc) {
      var %address = $gettok($gettok(%nc,2,62),1,60)
      var %phone = $gettok($gettok(%nc,4,62),1,60)
      [color:blue]; This splits %address into street number, street name, and apartment variables.
      ; It's optional depending on whether you really need them split apart like that...[/color]
      var %streetnum = $gettok(%address,1,32)
      var %streetname = $gettok($gettok(%address,2-,32),1,44)
      var %apt = $gettok(%address,2,44)
    }


Note that this assumes all apartment numbers have a comma before them. If that's not the case, swap the two 44's (commas) to 35's (#'s) and then $remove the commas from %streetname.

Notice the embedded sockread? In some cases, this is necessary. If not done properly, it can lead to some weird results, but when it is done correctly, you can get some lines that have no unique characters on them. You *could* use an IF to make this work in this case if you didn't want to use an embedded sockread... (perhaps regex would as well, for that matter). But, the embedded sockread is easier to do. laugh


Invision Support
#Invision on irc.irchighway.net
Page 2 of 2 1 2

Link Copied to Clipboard