mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
I have a text file with cities along with their zip codes and the state abbreviation, and the file is pretty large. It's 29470 lines. For the script I'm working on, I need to look up the city and state based on the zip code a person enters. I thought it might be better to load that into a hash table, but mIRC crashes when I load it. Is using $read the best option in this case? Thanks for any help.

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
You might try loadbuffing it into a custom window and then load the hash table from the custom window.

Code:
alias test {
  [color:green]; Create the hash table, the ratio here is 1:10, so 5000 can hold 50,000 items[/color]
  [color:green]; This leaves quite a bit of room for expansion, however you can lower it if you like[/color]
  hmake CitiesTable 5000
  [color:green]; Create a custom window, which is hidden (-h) called @Cities[/color]
  window -h @Cities
  [color:green]; Load all lines of the textfile into the custom window[/color]
  loadbuf @Cities textfile.txt
  [color:green]; %i is our counter variable for the while loop[/color]
  [color:green]; %ln is set equal to the number of lines in the custom window[/color]
  var %i = 1, %ln = $line(@Cities,0)
  while (%i <= %ln) {
    [color:green]; Loop through all lines of the custom window and add each to the hash table[/color]
    [color:green]; You will probably want to change the naming scheme here[/color]
    [color:green]; I'm using this format for example purposes only[/color]
    hadd CitiesTable $+(City,%i) $line(@Cities,%i)
    inc %i
  }
  [color:green]; Save the hash table[/color]
  hsave CitiesTable CitiesTable.hsh
  [color:green]; Close the custom window since it's no longer needed[/color]
  window -c @Cities
}


Not tested.

Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
Thanks for the idea. I loadbuffed it into a window, but I'm pretty new to custom windows and hash tables. How would I get the stuff from the window into a hash table and can I tell it to do all the lines or do I have to do a few at a time and loop it until I get them all? Thanks.

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Heh, you posted about the same time I edited my previous post. Have a look there for how to do it. If you need further help adding entries to the table, just post here what format the lines in the text file are in, but I think you should be able to figure it out.

Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
Thank you for the help. That worked. I have another issue I'm trying to work on. It's not related to hash tables, but this is all related to a weather bot I'm doing, so I decided to add to this thread and not start a new one. I'm working with sockets, and trying to pull a specific number out of XML code, but I think mIRC is having problems with how I was trying to do it because there are < and > signs in the XML. The basic socket code is this:
Code:
on *:sockread:weather:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
     [color:green] ;this line below is the one I'm trying to do [/color] 
     if ($left(%temptext,4) = &lt;loc) {
       [color:green];do stuff here[/color] 
      sockclose $sockname
    }  
    sockclose $sockname  
  }
}


The XML line I'm working with will be something like:
<loc id="USCA0638" type="1">Los Angeles, CA</loc>
I want to pull that USCA0638 out of the line to use in another search. That letter/number combination will be different for each location, but the rest of that line will be the same.

Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
I wrote a test alias to try to evaluate that line, and the alias works, but it doesn't work in remotes. The test alias is:
Code:
/isintest {
  var %a = &lt;loc id="94102" type="4"&gt;San Francisco, CA (94102)&lt;/loc&gt;
  if (loc id isin %a) {
    echo -a hello
  }
}

This echoes hello like it should, but I try to evaluate what's being read by $sockread, it doesn't work. I tried writing everything to a text file, and it is getting the right information, but it isn't catching the line I want. Here's the remote:
Code:
on *:sockread:weather:{
  if ($sockerr) {
    echo -a Error.
    halt
  }
  else {
    var %temptext
    sockread %temptext
    if (loc id isin %temptext) {
      msg $chan $gettok(%temptext,2,34)
    }  
  }
}

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Code:
alias test {
  var %c = &lt;loc id="USCA0638" type="1"&gt;Los Angeles, CA&lt;/loc&gt;
  echo -a $remove($gettok(%c,2,32),id=,")
}

Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
Thank you, but the alias works, the problem is that I can't get the remote to recognize when it has hit that line so I can do something with it. I'm not sure why. I need the remote to be able to know when it hits the line that starts with <loc id= so I can pull that number out. Thanks.

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
I'm not too familiar with sockets, but I have some basic knowledge of them. I can't seem to replicate your problem, when I ran a query on a game server and searched for text in a line, it worked as it should have. I don't see anything wrong in your code.

What is happening when it does the check? Can you give a block of lines that its reading with that line you're looking for included.

Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
This doesn't even seem to be a socket problem. It's getting all of the information. I put a write statement there to test it, and it wrote everything to a text file. The problem is just getting it to recognize when it hits that line, so I can get what I want out of it. Here's the XML for that page:
Code:
&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt; 
- &lt;!-- This document is intended only for use by authorized licensees of The Weather Channel. Unauthorized use is prohibited. Copyright 1995-2005, The Weather Channel Interactive, Inc. All Rights Reserved.
  --&gt; 
- &lt;search ver="2.0"&gt;
   [color:green]  &lt;loc id="94102" type="4"&gt;San Francisco, CA (94102)&lt;/loc&gt; [/color]
 &lt;/search&gt;

I've highlighted the line I want it to recognize.

Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Ok, well I threw that text into a file, all spacing in tact. I used your same code to find the line. It echos 94102 as expected.

Code:
alias test {
  var %i = 1, %ln = $lines(find.txt)
  while (%i &lt;= %ln) {
    var %temptext = $read(find.txt,%i)
    if (loc id isin %temptext) {
      echo -a $gettok(%temptext,2,34)
    }
    inc %i
  }
}

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
make sure you dont have another sockread "weather" in your remotes
it should do something, post all of your code for this

Last edited by MikeChat; 27/01/06 10:49 PM.
Joined: May 2005
Posts: 449
Fjord artisan
OP Offline
Fjord artisan
Joined: May 2005
Posts: 449
I found my mistake, and it's a stupid one, as usual, lol. I had that variable in the URL, and I wasn't testing with a nick, I was opening the socket manually, so it didn't equal anything. I also changed the position of two of my lines that set variables. Thanks for the help, though. I appreciate it.


Link Copied to Clipboard