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.

Pull top scorers from page and display...

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
z
zombie_gaz
Voice
Posts: 7
Joined: Wed Feb 25, 2009 7:40 pm

Pull top scorers from page and display...

Post by zombie_gaz »

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

http://www.4thegame.com/football-statis ... opscorers/

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/footbal ... efault.stm to display player, team and total would be fine. :\
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

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: Select all

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 :-

Image
I must have had nothing to do
z
zombie_gaz
Voice
Posts: 7
Joined: Wed Feb 25, 2009 7:40 pm

Small change

Post by zombie_gaz »

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

So '!topscorer 1-5' instead of '!topscorer 1 5'.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I expect you'd have to get somebody to make a different script
I must have had nothing to do
z
zombie_gaz
Voice
Posts: 7
Joined: Wed Feb 25, 2009 7:40 pm

Use - between intigers...

Post by zombie_gaz »

There's no way to change this? That really sucks. :\
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

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

Code: Select all

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 
}
Post Reply