|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
I'm trying to make this script that will look up each callsign in my log on www.qrz.com and get what country they're from. I know that the qrz site was having problems today, but it's up now, and the script still doesn't work. I noticed that %temptext was equal to something like "HTTP 200 OK" at one point, which I don't think is a good thing. The file that this is reading is a simple text file with each callsign on its own line. Here's the code:
on 1:sockopen:qrz: {
set %url /detail/ $+ $read("C:\Documents and Settings\Owner\Desktop\hams.txt",%ln)
sockwrite -n $sockname GET %url HTTP/1.1
sockwrite -n $sockname Host: www.qrz.com $+ $crlf $+ $crlf
}
on 1:sockread:qrz:{
if ($sockerr) {
echo -a Error.
halt
}
else {
sockread %temptext
if ($mid(%temptext,41,7) == Country) {
var %head = <tr bgcolor="#FFFFFF"><td align="right">
var %mid = </td><td><b>
var %end = </b></td></tr>
%text = %text $+ $chr(32) $+ $remove(%temptext,%head,%mid,%end)
write "C:\Documents and Settings\Owner\Desktop\hams2.txt" %text
unset %text
}
elseif ($left(%temptext,14) == <title>QRZ.COM) {
var %head = <title>QRZ.COM
var %mid = </td><td><b><a href="/callsign/N4BWR">
var %end = </title>
set %text $remove(%temptext,%head,%end)
}
}
%ln = %ln + 1
sockclose qrz
if (%ln >= $lines("C:\Documents and Settings\Owner\Desktop\hams.txt")) {
$qrz
}
}
alias qrz {
sockopen qrz www.qrz.com 80
}
If you want one or two callsigns to test it out, you can try NA1SS (the space station) and W1AW (ARRL headquarters). Thanks.
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
1. It sort of worked for me by removing the /sockclose command. 2. Maybe use this custom identifier to strip the HTML tags, to make life a little easier.
alias -l html {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Remove your sockclose line and you'll have no problems. Or, adjust it so that it doesn't close after the first line is received. Btw, it appears as though you're going to run into * /set: line too long errors.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
When I took out /sockclose, I got errors because the socket was already open, and I've only been able to get this to successfully write the first callsign and country.
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
on 1:sockopen:qrz: {
set %url /detail/ $+ $read("C:\Documents and Settings\Owner\Desktop\hams.txt",%ln)
sockwrite -n $sockname GET %url HTTP/1.1
sockwrite -n $sockname Host: www.qrz.com $+ $crlf $+ $crlf
}
on 1:sockread:qrz:{
if ($sockerr) {
echo -a Error.
halt
}
else {
sockread %temptext
if (Country isin %temptext) {
write "C:\Documents and Settings\Owner\Desktop\hams2.txt" $html(%temptext)
%ln = %ln + 1
if (%ln <= $lines("C:\Documents and Settings\Owner\Desktop\hams.txt"){
set %url $read("C:\Documents and Settings\Owner\Desktop\hams.txt",%ln)
qrz
}
}
}
}
alias qrz {
if (!%ln) set %ln 1
sockclose qrz
sockopen qrz www.qrz.com 80
}
alias -l html {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
I think it may need working on but try that.
|
|
|
|
Joined: May 2005
Posts: 449
Fjord artisan
|
OP
Fjord artisan
Joined: May 2005
Posts: 449 |
Thanks. I got this figured out before your latest reply, Andy. Here's a shortened version of the output. These are some of the ham radio contacts I've made lately: PY2BN Country:BRAZIL TI2JJP Country:COSTA RICA LU6FOV Country:ARGENTINA KI4MJO Country:USA YV4DYJ Country:VENEZUELA NP4A Country:USA ZP6DYA Country:BRAZIL YO9HP Country:ROMANIA KB0RGS Country:USA YU1XA Country:SERBIA CT3MD Country:PORTUGAL W1AW Country:USA KI4MJO Country:USA GB6MD Country:England - U.K. WW2SUB Country:USA NI4BK Country:USA HB9Z Country:SWITZERLAND F5BBD Country:FRANCE
I still need to work with it a bit to add the part about stopping when it has read the last line of the file, but this is what I have:
on 1:sockread:qrz:{
if ($sockerr) {
echo -a Error.
halt
}
else {
sockread %temptext
if ($mid(%temptext,41,8) == Country:) {
var %head = <tr bgcolor="#FFFFFF"><td align="right">
var %mid = </td><td><b>
var %end = </b></td></tr>
%text = %text $+ $chr(32) $+ $remove(%temptext,%head,%mid,%end)
write "C:\Documents and Settings\Owner\Desktop\hams2.txt" %text
unset %text
}
elseif ($left(%temptext,14) == <title>QRZ.COM) {
var %head = <title>QRZ.COM
var %mid = </td><td><b><a href="/callsign/ $+ %call $+ ">
var %end = </title>
set %text $remove(%temptext,%head,%end)
}
}
if (%temptext = </html>) {
%ln = %ln + 1
set %url /detail/ $+ $read("C:\Documents and Settings\Owner\Desktop\hams.txt",%ln)
set %call $read("C:\Documents and Settings\Owner\Desktop\hams.txt",%ln)
sockwrite -n $sockname GET %url HTTP/1.1
sockwrite -n $sockname Host: www.qrz.com $+ $crlf $+ $crlf
}
}
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
You can include the sockclose in multiple ways. One way is to just do it before opening a new one as shown. You can also do something like:
if (</html> isin %temptext) { sockclose qrz }
... or something similar. Note that you can adjust that so that it closes after the last line of data that you *need*. In other words, if you only needed the first 10 lines of text, you could make it close after that first 10 lines so that you don't waste bandwidth downloading a lot of extra html that isn't needed.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
In my above code add a simple else that should do the trick.
on 1:sockread:qrz:{
if ($sockerr) {
echo -a Error.
halt
}
else {
sockread %temptext
if (Country isin %temptext) {
echo -a $read(hams.txt,%ln) is $html(%temptext)
%ln = %ln + 1
if (%ln <= $lines(hams.txt)) {
set %url $read(hams.txt,%ln)
qrz
}
else { unset %ln }
}
}
}
It unsets the line number when it's finished. PY2BN Country:BRAZIL TI2JJP Country:COSTA RICA LU6FOV Country:ARGENTINA KI4MJO Country:USA YV4DYJ Country:VENEZUELA NP4A Country:USA ZP6DYA Country:BRAZIL YO9HP Country:ROMANIA KB0RGS Country:USA YU1XA Country:SERBIA CT3MD Country:PORTUGAL W1AW Country:USA KI4MJO Country:USA GB6MD Country:England - U.K. WW2SUB Country:USA NI4BK Country:USA HB9Z Country:SWITZERLAND F5BBD Country:FRANCE If it still doesn't work for you, there are others here available to help. It's my bed time now.
|
|
|
|
|