Not sure if I am doing this right, this is my first try at using sockets. All im trying to do is get it to echo back to me the billboard new releases. I am not sure if it is my script that has the problem or if it is the site that i am trying to access. This is what I have so far
Code:
alias sockettest {
sockopen toplist www.billboard.com 80
}
on *:SOCKOPEN:toplist: {
sockwrite -nt $sockname post www.billboard.com/bbcom/releases/releases_display.jsp?rollDate=0
sockwrite -nt $sockname HOST: billboard.com $+ $crlf $+ $crlf
sockwrite -nt $sockname Accept-Language: en-us
sockwrite -nt $sockname User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)
}
on *:SOCKREAD:toplist: {
if ($sockerr) {
echo -s SockError $sockname $sockerr
return
}
else {
var %temptext
sockread %temptext
echo -a %temptext
}
}
I also tried it on yahoo sports with no such luck. I think i am using the wrong post/get method this is what i have for yahoo
Code:
alias sockettest {
sockopen toplist www.yahoo.com 80
}
on *:SOCKOPEN:toplist: {
sockwrite -nt $sockname GET sports.yahoo.com/mlb/scoreboard
sockwrite -nt $sockname HOST: yahoo.com
sockwrite -nt $sockname Accept-Language: en-us
sockwrite -nt $sockname User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT)
}
on *:SOCKREAD:toplist: {
if ($sockerr) {
echo -s SockError $sockname $sockerr
return
}
else {
var %temptext
sockread %temptext
echo -a %temptext
}
}
Quote:
<h1>Sorry, Bad Request.</h1> Your browser sent a request that this server could not understand.<P> Invalid URI in request GET sports.yahoo.com/mlb/scoreboard<P> <p>Please check the URL for proper spelling and capitalization. If you're having trouble locating a destination on Yahoo!, try visiting the <strong><a
Now that I can get the script to work I got a few problems. I found some code by Riamus in his weather bot to get $htmlfree info.
Code:
on *:SOCKREAD:toplist: {
if ($sockerr) {
echo -s SockError $sockname $sockerr
return
}
else {
var %temptext
sockread %temptext
if (*<div class="searchResultAlb_Col_txt_1_1_1">* iswm %temptext) || (*<div class="searchResultAlb_Col_txt_1_2">* iswm %temptext) {
write socktemp.txt $htmlfree(%temptext)
}
}
}
alias -l htmlfree {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;)
return %x
}
It writes the album name and the artist on two seprate lines and has 4 tab spaces in front of it.
Quote:
10 Bare Essentials Artist: Bobby Bare
Thats how it writes to the txt file. What I cant figure out is how to get rid of the 4 tab spaces and put the album and artist on the same line. I tried a few different things but all with no success. The *<div class="searchResultAlb_Col_txt_1_1_1">* is the album line and *<div class="searchResultAlb_Col_txt_1_2">* is the artist line. Thanks
The artist and song data are probably on different lines in the html code. To get both items on one line, you need to store the first item in a variable when it arrives, and then write both items at the same time when the second arrives. Here is a pseudocode example:
if (song isin thisdata) { set %song $htmlfree($1-) } elseif (artist isin thisdata) { write file.txt %song $htmlfree($1-) }
hmm i thought i tried that but quess not because it worked perfect. The only thing is that there is 4 tab spaces in between each item. In the front on each line there is 4 tab spaces and the after the album name before the artist there is 4 more. I am sure it is in the $htmlfree but not to sure how that code works. This is what I have now
Code:
on *:SOCKREAD:toplist: {
if ($sockerr) {
echo -s SockError $sockname $sockerr
return
}
else {
var %temptext
sockread %temptext
if (*<div class="searchResultAlb_Col_txt_1_1_1">* iswm %temptext) {
set %song $htmlfree(%temptext)
}
elseif (*<div class="searchResultAlb_Col_txt_1_2">* iswm %temptext) {
write sockettemp.txt %song $htmlfree(%temptext)
}
}
}
alias -l htmlfree {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x,&nbsp;)
return %x
}