| View previous topic :: View next topic |
| Author |
Message |
zombie_gaz Voice
Joined: 25 Feb 2009 Posts: 7
|
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Thu Feb 26, 2009 12:28 pm Post subject: |
|
|
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 |
|
 |
zombie_gaz Voice
Joined: 25 Feb 2009 Posts: 7
|
Posted: Thu Feb 26, 2009 2:56 pm Post subject: Small change |
|
|
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 |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Thu Feb 26, 2009 3:11 pm Post subject: |
|
|
I expect you'd have to get somebody to make a different script _________________ I must have had nothing to do |
|
| Back to top |
|
 |
zombie_gaz Voice
Joined: 25 Feb 2009 Posts: 7
|
Posted: Thu Feb 26, 2009 3:13 pm Post subject: Use - between intigers... |
|
|
| There's no way to change this? That really sucks. :\ |
|
| Back to top |
|
 |
tomekk Master

Joined: 28 Nov 2008 Posts: 255 Location: Oswiecim / Poland
|
Posted: Thu Feb 26, 2009 4:34 pm Post subject: |
|
|
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 |
|
 |
|