io
(Europe/Berlin)
Topics viewed: 392893

Liga-Script


Liga-Script

Das folgende TCL-Skript entstand um mittels Eggdrop-Bot im IRC Bundesligaergebnisse abbilden zu können.

Das Skript bezieht Daten aus dem RSS-Feed von kicker online.

kicker online

Code in TCL

iobltool.tcl:

			# Bundesliga
			# by io 
			#
			# Script for the German Bundesliga 1,2 and 3 
			#
			#
			
			#
			# Konfiguration
			#
			
			set befehl "!bundesliga"
			
			set bldatumsformat "%A, %d. %B %Y"
			set bltoolname "iobltool"
			set blapi_url1 "http://rss.kicker.de/live/bundesliga"
			set blapi_url2 "http://rss.kicker.de/live/2bundesliga"
			set blapi_url3 "http://rss.kicker.de/live/3liga"
			set blcopyright "Powered by kicker online (http://kicker.de)"
			#
			# Programm
			#
			
			bind pub -|- $befehl iobltool:gettv
			
			package require md5
			package require tdom
			package require Thread
			package require fileutil
			package require http
			
			proc iobltool:strlen {string} {
			        set n 0
			        while {$string != ""} { set string [string range $string 1 end]; incr n }
			        return $n
			}
			
			proc iobltool:startgettv { nick hosv handle chan text} {
			        after [expr {int(1 * 1000)}] iobltool:thread:gettv $nick $hosv $handle $chan $text
			}
			
			proc iobltool:gettv { nick host handle chan text} {
			        set text [string trim $text]
			        global bldatumsformat blcopyright bltoolname blapi_url1 blapi_url2 blapi_url3
			        set url $blapi_url1
			        if {$text == 1} {
			                set url $blapi_url1
			        } elseif {$text == 2} {
			                set url $blapi_url2
			        } elseif {$text == 3} {
			                set url $blapi_url3
			        }
			        if {[string length $url] > 0} {
			                set validrequest 0
			                set textlist {}
			                set mylist {}
			                set mysender ""
			                set urllist {}
			                foreach c [split $text " "] {
			                        lappend mylist $c
			                }
			                set atext [lindex $mylist {0}]
			                if {[llength $mylist] > 0} {
			                        set mysender [string trim [lindex $mylist {1}]]
			                }
			                set all {}
			                set validrequest 1
			                set maxlength 20
			                if { $validrequest == 1 } {
			                        set myxml [iobltool:fetchXML $url]
			                        set doc [dom parse $myxml]
			                        set root [$doc documentElement]
			                        set xmlpath [$root selectNodes {//item}]
									foreach item $xmlpath {
			                                set zeile ""
			                                set titel [[$item selectNodes "title"] text]
			                                set link [[$item selectNodes "link"] text]
			
			                                if {[string length $titel] >= $maxlength} {
			                                        set maxlength [string length $titel]+1
			                                }
			
			                                lappend zeile $titel
			                                lappend zeile "| "
			                                set tinyurl [iobltool:tinyurl $link]
			                                lappend zeile $link
			
			                                lappend all $zeile
			                        }
			                }
			                if {[llength $all] > 0} {
			                        putserv "PRIVMSG $nick :Empfange Daten ..."
			                        foreach zeile $all {
			                                set tinyresult ""
			                                set mytitle [lindex $zeile 0]
			                                while {[string length $mytitle] < $maxlength} {
			                                        set spacer " "
			                                        set mytitle $mytitle$spacer
			                                }
			                                while {[string length $tinyresult] < 2} {
			                                        set tinyresult [iobltool:tinyurl [lindex $zeile 2]]
			                                }
			                                after [expr {int(1 * 1500)}] [putserv "PRIVMSG $nick :$mytitle [lindex $zeile 1] $tinyresult "]
			                        }
			                        after [expr {int(1 * 2500)}] [putserv "PRIVMSG $nick :io-Bundesliga-tool $blcopyright "]
			
			                } else {
			                        putserv "PRIVMSG $nick :Keine Treffer ..."
			                }
			        } else {
			                putserv "PRIVMSG $chan :$nick mag Fussi ..."
			        }
			}
			
			proc iobltool:tinyurl {url} {
			        set result {}
			        set query [::http::formatQuery url $url]
			        catch {
			                set tok [::http::geturl "http://tinyurl.com/api-create.php" -query $query]
			                upvar #0 $tok state
			                if {$state(status) == "ok" && $state(type) == "text/plain"} {
			                        set result [lindex [split $state(body) \n] 0]
			                }
			                ::http::cleanup $tok
			        }
			        return $result
			}
			
			proc iobltool:fetchXML {uri {recurse_limit 4}} {
			
			        set token [http::geturl $uri]
			        upvar #0 $token state
			        if {[http::status $token] != "ok" || [http::ncode $token] != 200} {
			                if {[http::ncode $token] == 302 && [incr recurse_limit -1] > 0} {
			                        array set meta $state(meta)
			                        set result [fetchXML $meta(Location) $recurse_limit]
			                        http::cleanup $token
			                        return $result
			                }
			                set err [http::code $token]
			                http::cleanup $token
			                return -code error $err
			        }
			        set xml [encoding convertfrom utf-8 [http::data $token]]
			        array set meta $state(meta)
			        http::cleanup $token
			
			        return $xml
			}
			
			putlog "*Loaded* iobltool by io"
			

TCL

Eine detaillierte Dokumentation zu TCL kann auf der folgenden Webseite gefunden werden. TCL Wiki"> >> TCL Wiki <<

(Last Modified: 06. May 2017 14:50:46)
(Lettercount: 3277)

Themen-Wolke

  Lindwurm     Wissen-1     Wissen-5     Flaeming     Feuerbach     De France     Ganymed     Compiz     Anke Engelke     Slawen     Kohlhaas     Goethe     Jueterbog     Adorno     TCL     Miss Platnum     Wissen-4     Marlene Dietrich     Schiller     Schlafparalyse     Wissen-3     Petridou     Shambhala     Kuttner     Moss     Wissen-2     Ingwer     Siemens     Pielhau     Anne Will     Stirner     Christen     Titeltt     Sokrates     Max Moor     WetterApp     Io     Debussy     Pinar Atalay     Weltmeister     Kim Fisher     Bloch     OpenCV     Schmidt     Müntzer     De Sade     Brandenburg     Hertha BSC     Bad Schandau     Ina Müller     Schelling     Antimarteria     Spargel     Martin Luther     Caren Miosga     Kant     Kallisto     Galilei     Zervakis     Perl     Stolz auf Sido     Fichte     Hegel     Heimat     Klemmkuchen     Maerchen     Novatlan     Impressum     Kontakt     Melanchthon     Kloster Zinna     Sagen     Dennewitz     Misanthrop     Philosophie     Jodie Foster     Sotschi     Riefenstahl     Sibel Kekilli     Richter     TV-Script     Daubner     Lierhaus     F1-Script     Nietzsche     Ginny Good     Xenophon     Schopenhauer     Freud     Liga-Script     Scholl-Latour     BVG     Fotos     Esmée Denters     Bedingfield     Judith Rakers     Jupiter     Statistik     Johann Tetzel     Tschirner     Platon     IRCnet     Schöneberger     Neukölln     Illusion     Berlin     Europa  

(Themecount: 107)