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 

Pull top scorers from page and display...

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
zombie_gaz
Voice


Joined: 25 Feb 2009
Posts: 7

PostPosted: Wed Feb 25, 2009 9:48 pm    Post subject: Pull top scorers from page and display... Reply with quote

I need a script that can do !topscorer # or !topscorer #-# using this web page.

http://www.4thegame.com/football-statistics/premiership/topscorers/

Obviously, it needs to make updates based on that web page.

So...

Doing !topscorer 1-2 would give you:
Top Scorer | Team | Prem | CC | FA | UEFA | CL | Other | Total
Nicolas Anelka | Chelsea | 15 | 0 | 4 | 0 | 2 | 0 | 21
Steven Gerrard | Liverpool | 9 | 0 | 1 | 0 | 5 | 0 | 15

If that's too much then just using http://news.bbc.co.uk/sport2/hi/football/eng_prem/top_scorers/default.stm to display player, team and total would be fine. :\
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Thu Feb 26, 2009 12:28 pm    Post subject: Reply with quote

script requires http package which should be available by default on eggdrops, but not windrops.

script requires +football flag setting in partyline for channel(s) you require it to function in, for example as follows :-

.chanset #eggTCL +football

as it stands, the script outputs text embelished with colour so the network/channel must allow it. for example a channel setting of +c on dalnet would prevent it working.

syntax is !topscorer <non-zero integer> ?non-zero integer?

Code:

package require http

setudef flag football

set vTimeout 10
set vUrl http://www.4thegame.com/football-statistics/premiership/topscorers/

bind PUB - !topscorer pTopScorer

proc pTopScorer {nick uhost hand channel txt} {
    global vTimeout vUrl
    if {[channel get $channel football]} {
        set arguments [string trim $txt]
        set min [lindex $arguments 0]
        if {[llength [split $arguments]] == 1} {set max $min} else {set max [lindex [split $arguments] 1]}
        if {([regexp {^[1-9][0-9]*$} $min]) && ([regexp {^[1-9][0-9]*$} $max])} {
            set agent [::http::config -useragent "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"]
            if {![catch {set http [::http::geturl $vUrl -timeout [expr {$vTimeout * 1000}]]}]} {
                switch -- [::http::status $http] {
                    "timeout" {putserv "PRIVMSG $channel :attempt to scrape $vUrl timed out after $vTimeout seconds"}
                    "error" {putserv "PRIVMSG $channel :attempt to scrape $vUrl returned error [::http::error $http]"}
                    "ok" {
                        switch -- [::http::ncode $http] {
                            200 {
                                regexp -- {wastarget="_blank">(.+?)<br>Prem} [::http::data $http] -> table
                                if {[info exists table]} {
                                    set table [regsub -all -- {<[^>]+>} $table " "]; set table [regsub -all -- {[\n]} $table ""]
                                    set table [regsub -all -- {[\s]{5}} $table \n]; set table [regsub -all -- {[\s]{2}\*} $table ""]
                                    set table [regsub -all -- {[\s]{2,4}} $table |]
                                    set playerlist [split $table \n]
                                    set count 0
                                    foreach line $playerlist {
                                        set itemlist [split $line |]
                                        if {[llength $itemlist] != 0} {
                                            incr count
                                            set player($count) [lindex $itemlist 0]; set team($count) [lindex $itemlist 1]
                                            set prem($count) [lindex $itemlist 2]; set cc($count) [lindex $itemlist 3]
                                            set fa($count) [lindex $itemlist 4]; set uefa($count) [lindex $itemlist 5]
                                            set cl($count) [lindex $itemlist 6]; set other($count) [lindex $itemlist 7]
                                            set total($count) [lindex $itemlist 8]
                                        }
                                    }
                                    switch -- $count {
                                        0 {putserv "PRIVMSG $channel :top score table found from $vUrl but empty"}
                                        default {
                                            if {[expr {$min <= $max}]} {
                                                if {[expr {$min <= $count}]} {
                                                    for {set loop $min} {$loop <= $max} {incr loop} {
                                                        if {[info exists player($loop)]} {
                                                            lappend outputlist \00312$player($loop)\003 ($team($loop)) Premier League ($prem($loop))
                                                            lappend outputlist Carling Cup ($cc($loop)) FA Cup ($fa($loop)) UEFA Cup ($uefa($loop))
                                                            lappend outputlist Champions League ($cl($loop)) Other ($other($loop)) Total ($total($loop))
                                                            set output [regsub -all -- {\(} [join $outputlist] \(\00314]
                                                            set output [regsub -all -- {\)} $output \003\)]
                                                            putserv "PRIVMSG $channel :$output"
                                                            unset outputlist
                                                        }
                                                    }
                                                } else {putserv "PRIVMSG $channel :results from $vUrl do not include top scorer $min onwards"}
                                            } else {putserv "PRIVMSG $channel :the first argument must be equal to or less than any second argument"}
                                        }
                                    }
                                } else {putserv "PRIVMSG $channel :top score table not found from $vUrl"}
                            }
                            default {putserv "PRIVMSG $channel :attempt to scrape $vUrl returned ncode [::http::ncode $http]"}
                        }
                    }
                }
                ::http::cleanup $http
            } else {putserv "PRIVMSG $channel :attempted connection to $vUrl failed"}
        } else {putserv "PRIVMSG $channel :correct syntax is !topscorer <non-zero integer> ?integer?"}
    }
        return 0
}


example output as follows :-


_________________
I must have had nothing to do
Back to top
View user's profile Send private message
zombie_gaz
Voice


Joined: 25 Feb 2009
Posts: 7

PostPosted: Thu Feb 26, 2009 2:56 pm    Post subject: Small change Reply with quote

What about if I wanted it to use input in the form #-# instead of # #?

So '!topscorer 1-5' instead of '!topscorer 1 5'.
Back to top
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Thu Feb 26, 2009 3:11 pm    Post subject: Reply with quote

I expect you'd have to get somebody to make a different script
_________________
I must have had nothing to do
Back to top
View user's profile Send private message
zombie_gaz
Voice


Joined: 25 Feb 2009
Posts: 7

PostPosted: Thu Feb 26, 2009 3:13 pm    Post subject: Use - between intigers... Reply with quote

There's no way to change this? That really sucks. :\
Back to top
View user's profile Send private message
tomekk
Master


Joined: 28 Nov 2008
Posts: 255
Location: Oswiecim / Poland

PostPosted: Thu Feb 26, 2009 4:34 pm    Post subject: Reply with quote

fix, works with !topscorer X, !topscorer X X, !topscorer X-X

Code:
package require http

setudef flag football

set vTimeout 10
set vUrl http://www.4thegame.com/football-statistics/premiership/topscorers/

bind PUB - !topscorer pTopScorer

proc pTopScorer {nick uhost hand channel txt} {
    global vTimeout vUrl
    if {[channel get $channel football]} {
        set arguments [string trim $txt]
   set args_len [llength [split $arguments]]

   if {$args_len == 1} {
      if {[regexp {^[1-9]+\-[1-9]+$} $arguments]} {
         set arg_split [split $arguments "-"]
         set min [lindex $arg_split 0]
         set max [lindex $arg_split 1]
      } {
         set min $arguments
         set max $arguments
      }
   } {
      set arg_split [split $arguments]
      set min [lindex $arg_split 0]
      set max [lindex $arg_split 1]
   }

   if {([regexp {^[1-9][0-9]*$} $min]) && ([regexp {^[1-9][0-9]*$} $max])} {
            set agent [::http::config -useragent "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"]
            if {![catch {set http [::http::geturl $vUrl -timeout [expr {$vTimeout * 1000}]]}]} {
                switch -- [::http::status $http] {
                    "timeout" {putserv "PRIVMSG $channel :attempt to scrape $vUrl timed out after $vTimeout seconds"}
                    "error" {putserv "PRIVMSG $channel :attempt to scrape $vUrl returned error [::http::error $http]"}
                    "ok" {
                        switch -- [::http::ncode $http] {
                            200 {
                                regexp -- {wastarget="_blank">(.+?)<br>Prem} [::http::data $http] -> table
                                if {[info exists table]} {
                                    set table [regsub -all -- {<[^>]+>} $table " "]; set table [regsub -all -- {[\n]} $table ""]
                                    set table [regsub -all -- {[\s]{5}} $table \n]; set table [regsub -all -- {[\s]{2}\*} $table ""]
                                    set table [regsub -all -- {[\s]{2,4}} $table |]
                                    set playerlist [split $table \n]
                                    set count 0
                                    foreach line $playerlist {
                                        set itemlist [split $line |]
                                        if {[llength $itemlist] != 0} {
                                            incr count
                                            set player($count) [lindex $itemlist 0]; set team($count) [lindex $itemlist 1]
                                            set prem($count) [lindex $itemlist 2]; set cc($count) [lindex $itemlist 3]
                                            set fa($count) [lindex $itemlist 4]; set uefa($count) [lindex $itemlist 5]
                                            set cl($count) [lindex $itemlist 6]; set other($count) [lindex $itemlist 7]
                                            set total($count) [lindex $itemlist 8]
                                        }
                                    }
                                    switch -- $count {
                                        0 {putserv "PRIVMSG $channel :top score table found from $vUrl but empty"}
                                        default {
                                            if {[expr {$min <= $max}]} {
                                                if {[expr {$min <= $count}]} {
                                                    for {set loop $min} {$loop <= $max} {incr loop} {
                                                        if {[info exists player($loop)]} {
                                                            lappend outputlist \00312$player($loop)\003 ($team($loop)) Premier League ($prem($loop))
                                                            lappend outputlist Carling Cup ($cc($loop)) FA Cup ($fa($loop)) UEFA Cup ($uefa($loop))
                                                            lappend outputlist Champions League ($cl($loop)) Other ($other($loop)) Total ($total($loop))
                                                            set output [regsub -all -- {\(} [join $outputlist] \(\00314]
                                                            set output [regsub -all -- {\)} $output \003\)]
                                                            putserv "PRIVMSG $channel :$output"
                                                            unset outputlist
                                                        }
                                                    }
                                                } else {putserv "PRIVMSG $channel :results from $vUrl do not include top scorer $min onwards"}
                                            } else {putserv "PRIVMSG $channel :the first argument must be equal to or less than any second argument"}
                                        }
                                    }
                                } else {putserv "PRIVMSG $channel :top score table not found from $vUrl"}
                            }
                            default {putserv "PRIVMSG $channel :attempt to scrape $vUrl returned ncode [::http::ncode $http]"}
                        }
                    }
                }
                ::http::cleanup $http
            } else {putserv "PRIVMSG $channel :attempted connection to $vUrl failed"}
        } else {putserv "PRIVMSG $channel :correct syntax is !topscorer <non-zero integer> ?integer?"}
    }
        return 0
}
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 -> Script Requests 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