io
(Europe/Berlin)
Topics viewed: 392831

TV-Script


TV-Script

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

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

tvspielfilm

Code in TCL

ioitvtool.tcl:

			# TV-Tool
			# by io 
			#
			# Script for the tv page tvspielfilm.de 
			#
			#
			
			#
			# Konfiguration
			#
			
			set befehl "!tv"
			
			set tvdatumsformat "%A, %d. %B %Y"
			set tvtoolname "iotvtool"
			set tvapi_url "http://www.tvspielfilm.de/tv-programm/rss/"
			set tvcopyright "Powered by tvspielfim.de (http://tvspielfim.de)"
			#
			# Programm
			#
			
			bind pub -|- $befehl iotvtool:gettv
			
			package require md5
			package require tdom
			package require Thread
			package require fileutil
			
			proc iotvtool:readfile { filename } {
			        set fp [open $filename]
			        set text ""
			        while {-1 != [gets $fp line]} {
			                append text $line
			        }
			        close $fp
			        return $text
			}
			
			proc iotvtool:writetofile { filename data  } {
			        set fileId [open $filename "w"]
			        puts -nonewline $fileId $data
			        close $fileId
			}
			
			proc iotvtool:lpick list {
			    lindex $list [expr {int(rand()*[llength $list])}]
			}
			
			proc iotvtool:strlen {string} {
			        set n 0
			        while {$string != ""} { set string [string range $string 1 end]; incr n }
			        return $n
			}
			
			proc iotvtool:lrandomint {max} {
			    return [expr {int(rand()*$max) + 1}]
			}
			
			proc iotvtool:startgettv { nick hosv handle chan text} {
			        after [expr {int(1 * 1000)}] iotvtool:thread:gettv $nick $hosv $handle $chan $text
			}
			
			proc iotvtool:gettv { nick host handle chan text} {
			        set text [string trim $text]
			        global tvdatumsformat tvcopyright tvtoolname tvapi_url
			        set url $tvapi_url
			        if {[string length $text] > 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] > 1} {
			                        set mysender [string trim [lindex $mylist {1}]]
			                }
			                if { $atext == "primetime" || $atext == "Primetime" || $atext == "PrimeTime" } {
			                        append url "heute2015.xml"
			                        set validrequest 1
			                } elseif { $atext == "now" || $atext == "Now" || $atext == "jetzt" || $atext == "Jetzt" } {
			                        append url "jetzt.xml"
			                        set validrequest 1
			                } elseif { $atext == "Filme" || $atext == "filme" || $atext == "films" || $atext == "Films" } {
			                        append url "filme.xml"
			                        set validrequest 1
			                } elseif { $atext == "spaeter" || $atext == "Spaeter" || $atext == "later" || $atext == "Later" } {
			                        append url "heute2200.xml"
			                        set validrequest 1
			                } elseif { $atext == "Tipps" || $atext == "Tip" || $atext == "tip" || $atext == "tipps" } {
			                        append url "tipps.xml"
			                        set validrequest 1
			                } else {
			                        set validrequest 2
			                        set urlpre1 $url
			                        set urlpre2 $url
			                        set urlpre3 $url
			                        set urlpre4 $url
			                        set urlpre5 $url
			                        append urlpre1 "heute2015.xml"
			                        append urlpre2 "jetzt.xml"
			                        append urlpre3 "filme.xml"
			                        append urlpre4 "heute2200.xml"
			                        append urlpre5 "tipps.xml"
			
			                        lappend urllist $urlpre1
			                        lappend urllist $urlpre2
						lappend urllist $urlpre3
			                        lappend urllist $urlpre4
			                        lappend urllist $urlpre5
			                        set mysender $text
			                }
			                set all {}
			                if { $validrequest == 1 } {
			                        set myxml [iotvtool:fetchXML $url]
			                        set doc [dom parse $myxml]
			                        set root [$doc documentElement]
			                        set xmlpath [$root selectNodes {//item}]
			                        foreach item $xmlpath {
			                                set zeile ""
			                                set sendung [lindex [$item selectNodes "title"] 0]
			                                set titlelist [split [$sendung text] "|"]
			                                set zeit [string trim [lindex $titlelist 0]]
			                                lappend zeile $zeit
			                                set sender [string trim [lindex $titlelist 1]]
			                                lappend zeile $sender
			                                set titel [string trim [lindex $titlelist 2]]
			                                lappend zeile $titel
			                                set description [lindex [$item selectNodes "description"] 0]
			                                set beschreibung [join [lrange [split [$description text]] 0 7]]
			                                if { [regexp -all {\w+} [$description text]] > 8 } {
			                                        append beschreibung " ..."
			                                }
			                                lappend zeile $beschreibung
			                                if { [string match "0*" [$sendung text]] || [string match "1*" [$sendung text]] || [string match "2*" [$sendung text]] } {
			                                        if { [string length $mysender] > 0 } {
			                                                if { [string match "ard" $mysender] || [string match "ARD" $mysender] } {
			                                                        set mysender "Das Erste"
			                                                } elseif { [string match "pro7" $mysender] || [string match "Pro7" $mysender] } {
			                                                        set mysender "ProSieben"
			                                                } elseif { [string match "sat1" $mysender] || [string match "Sat1" $mysender] } {
			                                                        set mysender "SAT.1"
			                                                }
			                                                set mysender1 $mysender
			                                                set mysender2 $mysender
			                                                set myupper [string toupper $mysender1]
			                                                set mylower [string tolower $mysender2]
			                                                if { [string match "*$mylower*" [string tolower [lindex $zeile 1]]] || [string match "*$myupper*" [string toupper [lindex $zeile 1]]] || [string match "*$mysender*" [lindex $zeile 1]] } {
			                                                        lappend all $zeile
			                                                }
			                                        } else {
			                                                lappend all $zeile
			                                        }
			                                }
			                        }
			                } elseif { $validrequest == 2  } {
						foreach currurl $urllist {
			                                set myxml [iotvtool:fetchXML $currurl]
			                                set doc [dom parse $myxml]
			                                set root [$doc documentElement]
			                                set xmlpath [$root selectNodes {//item}]
			                                foreach item $xmlpath {
			                                        set zeile ""
			                                        set sendung [lindex [$item selectNodes "title"] 0]
			                                        set titlelist [split [$sendung text] "|"]
			                                        set zeit [string trim [lindex $titlelist 0]]
			                                        lappend zeile $zeit
			                                        set sender [string trim [lindex $titlelist 1]]
			                                        lappend zeile $sender
			                                        set titel [string trim [lindex $titlelist 2]]
			                                        lappend zeile $titel
			                                        set description [lindex [$item selectNodes "description"] 0]
			                                        set beschreibung [join [lrange [split [$description text]] 0 7]]
			                                        if { [regexp -all {\w+} [$description text]] > 8 } {
			                                                append beschreibung " ..."
			                                        }
			                                        lappend zeile $beschreibung
			                                        if { [string match "0*" [$sendung text]] || [string match "1*" [$sendung text]] || [string match "2*" [$sendung text]] } {
			                                                if { [string length $mysender] > 0 } {
			                                                        if { [string match "ard" $mysender] || [string match "ARD" $mysender] } {
			                                                                set mysender "Das Erste"
			                                                        } elseif { [string match "pro7" $mysender] || [string match "Pro7" $mysender] } {
			                                                                set mysender "ProSieben"
			                                                        } elseif { [string match "sat1" $mysender] || [string match "Sat1" $mysender] } {
			                                                                set mysender "SAT.1"
			                                                        }
			                                                        set mysender1 $mysender
			                                                        set mysender2 $mysender
			                                                        set myupper [string toupper $mysender1]
			                                                        set mylower [string tolower $mysender2]
			                                                        if { [string match "*$mylower*" [string tolower [lindex $zeile 1]]] || [string match "*$myupper*" [string toupper [lindex $zeile 1]]] || [string match "*$mysender*" [lindex $zeile 1]] } {
			                                                                lappend all $zeile
			                                                        }
			                                                }
			                                        }
			                                }
			                        }
			                }
			                if {[llength $all] > 0} {
			                        putserv "PRIVMSG $nick :Empfange Daten ..."
			                        set all [lsort -unique $all]
			                        set all [lsort -index 0 $all]
			                        foreach zeile $all {
			                                after [expr {int(1 * 1000)}] [putserv "PRIVMSG $nick :[lindex $zeile 0] [lindex $zeile 1] | [lindex $zeile 2] | [lindex $zeile 3]"]
			                        }
			
			                } else {
			                        putserv "PRIVMSG $nick :Keine Treffer ..."
			                        putserv "PRIVMSG $nick :$nick, mögliche !tv Argumente sind: Now \[Sender\], Later \[Sender\], Primetime \[Sender\], Tipps \[Sender\], Films \[Sender\] und  .."
			                }
			        } else {
					putserv "PRIVMSG $chan :$nick schaut TV ..."
			        }
			}
			
			proc iotvtool: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* iotvtool by io"
			

TCL

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

(Last Modified: 06. May 2017 15:24:04)
(Lettercount: 6052)

Themen-Wolke

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

(Themecount: 107)