egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

fetching data from web.

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
iamdeath
Master


Joined: 11 Feb 2005
Posts: 323
Location: *HeLL*

PostPosted: Wed Feb 25, 2009 12:14 am    Post subject: fetching data from web. Reply with quote

Hi I am trying to fetch data from the web and paste it on IRC using MSG or NOTICE method, but for some reasons its not working.

Code:
# 1 : notice $nick
# 2 : privmsg $nick
# 3 : privmsg $channel
set cricketmethod 2

### Events
bind pub - "!rating" rating

package require http

proc rating {nick uhost handle channel text} {
  switch -- [string tolower [lindex [split $text] 0]] {
    odi {
      rating:download $nick $channel odi
    }
    test {
      rating:download $nick $channel test
    }
    default {
      putquick "NOTICE $nick :Commands:"
      putquick "NOTICE $nick :!rating ODI"
      putquick "NOTICE $nick :!rating TEST"
    }
  }
}

proc rating:download {nick chan class} {
  global data
  switch -exact -- $::cricketmethod {
    "1" {set method "notice" ; set who "$nick"}
    "2" {set method "privmsg" ; set who "$nick"}
    "3" {set method "privmsg" ; set who "$chan"}
  }
putlog "Reply 2."
  set url "http://icc-cricket.yahoo.com/rankings/rankings.html"
  set data [getwebdata $url]
  if {$data==0} {
    putserv "$method $who :There was an error fetching the data. Contact an admin to report this or try again later."
    return
  }
putlog "Reply 3."
  set foundstart 0
putlog "Reply 4."
  foreach line [split $data \r\n] {
putlog "Reply 5."
putlog [string match "<div id=\"rankings-header\"><a name=\"$class\">" $line]; putlog "line:$line";
    if {[string match -nocase "<div id=\"rankings-header\"><a name=\"$class\">" $line]} {
putlog "Reply 6."
      set word "\037\002[string range $line [expr 40 + [string length $class] -3] [expr [string length $line]-11]]\002\037"
      regsub -all {Reliance Mobile ODI Championship} $word "\00300,04ICC ONE-DAY Cricket Ratings.\003" word
      regsub -all {Reliance Mobile Test Championship} $word "\00300,03ICC TEST Cricket Ratings.\003" word
      putserv "$method $who :$word"
putlog "Reply 1."
      set foundstart 1
      set output ""
    } elseif {$foundstart && [string match -nocase {<div class="rankings_bottom">*</div>*} $line]} {
      # output the date
      regsub -all "<div style=\"float:left;padding-left:10px;\">" $info " " info
      ## regsub -all -- {<div .*?>} $line "" line
      ## regsub -all -- {</div>} $line " " line   
      set word [string range $line 29 [expr [string length $line]-15]]
      putserv "$method $who :$word"
      return
    } elseif {$foundstart} {
      # firstcol - the ranking
      if {[string match -nocase {<div class="firstcol">*</div>} $line]} {
        set word [string range $line 25 [expr [string length $line]-11]]
        append output "[format %-3s $word]"
      # secondcol = info bold
      } elseif {[string match -nocase {<div class="secondcol"><b>*</b></div>} $line]} {
        set word [string range $line 26 [expr [string length $line]-11]]
        append output "[format %-16s "\002$word\002"]"
      # secondcol = info normal
      } elseif {[string match -nocase {<div class="secondcol">*</div>} $line]} {
        set word [string range $line 23 [expr [string length $line]-7]]
        append output "[format %-15s $word]"
      # output everything
      } elseif {[string match -nocase {</div>} $line]} {
        putserv "$method $who :$output"
        set output ""
      }
    }
  }
}


The problem is here I think:

Code:
putlog "Reply 5."
putlog [string match "<div id=\"rankings-header\"><a name=\"$class\">" $line]; putlog "line:$line";
    if {[string match -nocase "<div id=\"rankings-header\"><a name=\"$class\">" $line]} {


P.S: It's not the complete script.

Can anyone tell me what could be the problem?

Thanks.
iamdeath
_________________
|AmDeAtH @ Undernet


Death is only the *Beginning*...
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber