This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

little problem.

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

little problem.

Post by iamdeath »

Code: Select all

   while {[gets $sock html] >= "0"} { 
      if {[string match -nocase "*<tr valign=top*>*" $html] == "1"} { 
        set x "0" 
        set line "" 
        set color "$html" 
      } elseif {[string match -nocase "*<td nowrap>*" $html] == "1"} { 
        set line "${line}[lrange [gets $sock] 0 1] " 
  
        if {[incr x] >= "2"} { 
          gets $sock html 
          gets $sock html 
          while {[gets $sock html] >= "0" 

 [string match -nocase "*>Forecast<*" $html] == "0"} { 
            if {[string match -nocase "*<br>*" $html] == "1" || [string match -nocase "*</td>*" $html] == "1"} { 
              regexp {.html">(.+)</a>} $html match html 
              regexp {(.+)<br>} $html match html 
              regexp {(.+) </td>} $html match html 
              set line "${line} ${html}." 
            } 
          } 
          nextmatch:line $nick $color $line 
        } 
  
      } 
    } 
I think here is the error, can you check what could possibily be wrong in that code, something here is missing:

Code: Select all

          while {[gets $sock html] >= "0" 

 [string match -nocase "*>Forecast<*" $html] == "0"} { 
Could you guide me please.

Thanks
|AmDeAtH @ Undernet
Death is only the *Beginning*...
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Error msgs, specifically the .set errorInfo debug, would be helpful..
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

Code: Select all

[21:03] <|AmDeAtH> .set errorInfo debug
[21:03] <Cricket`-> [21:03] #iamdeath# set errorInfo debug
[21:03] <Cricket`-> Ok, set.
[21:03] <Cricket`-> [21:03] Tcl error [nextmatch]: syntax error in expression "[gets $sock html] >= "0" 
[21:03] <Cricket`->  [string match -nocase "*>Forecas...": extra tokens at end of expression
Thats the error I get.
|AmDeAtH @ Undernet
Death is only the *Beginning*...
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

There's a chunk of code missing...

Also a hint, the decoding done by KrzychuG in your other thread is flawed, and will cause this error.

Doing a proper decoding would reveal that the conditionals "[gets $sock html] >= 0" and "[string match -nocase "*>Forecast<*" $html] == 0" should be combined using logical AND (&&), creating a proper if-clause.
NML_375
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

nml375 wrote:There's a chunk of code missing...

Also a hint, the decoding done by KrzychuG in your other thread is flawed, and will cause this error.

Doing a proper decoding would reveal that the conditionals "[gets $sock html] >= 0" and "[string match -nocase "*>Forecast<*" $html] == 0" should be combined using logical AND (&&), creating a proper if-clause.
Thanks alot nml for pointing the mistake out I have now modified my script but I got some errors take a look please:

Code: Select all

    while {[gets $sock html] >= "0"} {
      if {[string match -nocase "*<tr valign=top*>*" $html] == "1"} {
        set x "0"
        set line ""
        set color "$html"
      } elseif {[string match -nocase "*<td nowrap>*" $html] == "1"} {
        set line "${line}[lrange [gets $sock] 3 4] "
        if {[incr x] >= "2"} {
          gets $sock html
          gets $sock html
          while {[gets $sock html] >= "0"} {
            if {[string match -nocase "*>Forecast<*" $html] == "0"} {
            if {[string match -nocase "*<br>*" $html] == "1" || [string match -nocase "*</td>*" $html] == "1"} {
              regexp {.html">(.+)</a>} $html match html
              regexp {(.+)<br>} $html match html
              regexp {(.+) </td>} $html match html
              set line "${line} ${html}."
            }
          }
          nextmatch:line $nick $color $line
        }

      }
    }
}
The bot is taking text from:

LINK

Here is what I get the reply from the bot now:

Code: Select all

[23:07] <Cricket`-> Forthcoming Live Coverage
[23:07] <Cricket`-> Date          Time             Match
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>. Pakistan v South Africa at Lahore.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>. Pakistan v South Africa at Lahore. 1st ODI.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>. Pakistan v South Africa at Lahore. 1st ODI. </td>.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>. Pakistan v South Africa at Lahore. 1st ODI. </td>. </td>.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>. Pakistan v South Africa at Lahore. 1st ODI. </td>. </td>. </td>.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>. Pakistan v South Africa at Lahore. 1st ODI. </td>. </td>. </td>. Dolphins v Titans at Durban.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>. Pakistan v South Africa at Lahore. 1st ODI. </td>. </td>. </td>. Dolphins v Titans at Durban. SuperSport Series.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>. Pakistan v South Africa at Lahore. 1st ODI. </td>. </td>. </td>. Dolphins v Titans at Durban. SuperSport Series. </td>.
[23:07] <Cricket`-> 17</span> India  v Australia      at Mumbai. 7th ODI. </td>. </td>. </td>. Pakistan v South Africa at Lahore. 1st ODI. </td>. </td>. </td>. Dolphins v Titans at Durban. SuperSport Series. </td>. </td>.
and then bot crashes:

Code: Select all

[23:07] * Quits: Cricket`- (cricket@cricket.users.undernet.org) (Excess Flood)
The bot is supposed to show Date: Time: Teams and then Venue. Could you please suggest me more thank you soo much.

iamdeath
|AmDeAtH @ Undernet
Death is only the *Beginning*...
User avatar
iamdeath
Master
Posts: 323
Joined: Fri Feb 11, 2005 2:32 pm
Location: *HeLL*
Contact:

Post by iamdeath »

Code: Select all

  #--- Download Info
  if {[catch {set sock "[socket content-usa.cricinfo.com 80]"} error] == "0"} {
    puts $sock "GET /ci/content/match/fixtures/live.html HTTP/1.0"
    puts $sock "Accept: text/html"
    puts $sock "Host: content-usa.cricinfo.com"
    puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
    puts $sock "Connection: close"
    puts $sock ""
    flush $sock

    #--- Header
    putquick "PRIVMSG $nick :\037\00300,06Forthcoming Live Coverage\003\037"
    putquick "PRIVMSG $nick :\037Date          Time             Match\037"

    #--- Filtering Info
    while {[gets $sock html] >= "0"} {
      if {[string match -nocase "*<tr valign=top*>*" $html] == "1"} {
        set x "0"
        set line ""
        set color "$html"
      } elseif {[string match -nocase "*<td nowrap>*" $html] == "1"} {
        set line "${line}[lrange [gets $sock] 0 1] "

        if {[incr x] >= "2"} {
          gets $sock html
          gets $sock html
          while {[gets $sock html] >= "0" && [string match -nocase "*>Forecast<*" $html] == "0"} {
            if {[string match -nocase "*<br>*" $html] == "1" || [string match -nocase "*</td>*" $html] == "1"} {
              regexp {.html">(.+)</a>} $html match html
              regexp {(.+)<br>} $html match html
              regexp {(.+) </td>} $html match html
              set line "${line} ${html}."
            }
          }
          nextmatch:line $nick $color $line
        }

      }
    }

    #--- Footer
    putquick "PRIVMSG $nick :\037\00300,06Current Date: [strftime "%a, %d %b %Y %H:%M:%S"]\003\037"

    close $sock
  } else {
    putquick "NOTICE $nick :Timeout while querying Server."
  }
}
proc nextmatch:line {nick color text} {
  if {[string match -nocase "*class=?blue?*" $color] == "1"} {
    putquick "PRIVMSG $nick :\00306,15[lrange $text 0 1] [string repeat " " [expr 10 - [string length "[lrange $text 0 1]"]]] [lrange $text 2 3]      [lrange $text 4 end]\003"
  } else {
    putquick "PRIVMSG $nick :[lrange $text 0 1] [string repeat " " [expr 10 - [string length "[lrange $text 0 1]"]]] [lrange $text 2 3]      [lrange $text 4 end]"
  }
}
The reply I get is:

Code: Select all

[00:38] <Cricket`-> Forthcoming Live Coverage
[00:38] <Cricket`-> Date          Time             Match
[00:38] <Cricket`-> <span style=\"vertical-align:  06:30 GMT      Namibia v Canada at Windhoek. ICC Intercontinental Cup.
[00:38] <Cricket`-> <span style=\"vertical-align:  08:00 GMT      Border v South Western Districts at East London. SAA Provincial Three-Day Challenge.
[00:38] <Cricket`-> <span style=\"vertical-align:  08:00 GMT      Eastern Province v Western Province at Port Elizabeth. SAA Provincial Three-Day Challenge.
[00:38] <Cricket`-> <span style=\"vertical-align:  08:00 GMT      Gauteng v Free State at Dobsonville. SAA Provincial Three-Day Challenge.
[00:38] <Cricket`-> <span style=\"vertical-align:  08:00 GMT      North West v Easterns at Potchefstroom. SAA Provincial Three-Day Challenge.
[00:38] <Cricket`-> <span style=\"vertical-align:  08:30 GMT      South African Invitation XI v New Zealanders at Bloemfontein. Tour Match.
[00:38] <Cricket`-> <span style=\"vertical-align:  08:30 GMT      Pakistan v South Africa at Multan. 4th ODI.
[00:38] <Cricket`-> <span style=\"vertical-align:  09:00 GMT      India Red v India Green at Ahmedabad. NKP Salve Challenger Trophy.
[00:39] <Cricket`-> <span style=\"vertical-align:  06:30 GMT      Kenya v Bermuda at Nairobi (Gym). 
[00:39] <Cricket`-> <span style=\"vertical-align:  06:00 GMT      Pakistan v South Africa at Lahore. 5th ODI.
[00:39] <Cricket`-> <span style=\"vertical-align:  08:00 GMT      Griqualand West v North West at Kimberley. SAA Provincial Three-Day Challenge.
[00:39] <Cricket`-> <span style=\"vertical-align:  08:00 GMT      Northerns v Free State at Centurion. SAA Provincial Three-Day Challenge.
[00:39] <Cricket`-> <span style=\"vertical-align:  08:30 GMT      South Africa A v New Zealanders at Potchefstroom. Tour Match.
[00:39] <Cricket`-> Current Date: Fri, 26 Oct 2007 12:38:46
You see it's not showing date in the first place but showing:

Code: Select all

<span style=\"vertical-align: 
can I get rid of it?

The source if:

http://content-pak.cricinfo.com/ci/cont ... /live.html

Thanks.
|AmDeAtH @ Undernet
Death is only the *Beginning*...
Post Reply