io
(Europe/Berlin)
Topics viewed: 38345

F1-Script


F1-Script

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

Das Skript bezieht Daten aus dem RSS-Feed von formel1.de.

formel1.de

Code in TCL

iof1tool.tcl:

			
			# Formel1
			# by io 
			#
			# Script for the Formula 1 news 
			#
			#
			
			#
			# Konfiguration
			#
			
			set befehl "!f1"
			
			set f1datumsformat "%A, %d. %B %Y"
			set f1toolname "iof1tool"
			set f1api_url1 "http://www.formel1.de/rss/news/feed.xml"
			set f1api_url2 "http://www.formel1.de/rss/formel-1/feed.xml"
			set f1copyright "Powered by formel1.de (http://formel1.de)"
			
			#
			# Programm
			#
			
			bind pub -|- $befehl iof1tool:gettv
			
			package require md5
			package require tdom
			package require Thread
			package require fileutil
			package require http
			
			proc iof1tool:gettv { nick host handle chan text} {
			        set text [string trim $text]
			        global f1datumsformat f1copyright f1toolname f1api_url1 f1api_url2
			        set url ""
			        if {$text == "news"} {
			                set url $f1api_url1
			        } elseif {$text == "all"} {
			                set url $f1api_url2
			        }
			        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 [iof1tool: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 [iof1tool: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 [iof1tool: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-F1-tool $f1copyright "]
			
			                } else {
			                        putserv "PRIVMSG $nick :Keine Treffer ..."
			                }
			        } else {
			                putserv "PRIVMSG $chan :$nick schaut nun Formel1 ..."
			        }
			}
			
			proc iof1tool: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 iof1tool: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* iof1tool by io"
							
			

TCL

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

(Last Modified: 10. June 2017 16:31:18)
(Lettercount: 2934)

Themen-Wolke

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

(Themecount: 107)