Code: Select all
Fehler vom Webserver: etag {"d65310beb378828916b842c4af0730a2"} content-type {text/html; charset=iso-8859-1} cache-control {public, max-age=300, must-revalidate} expires {Fri, 31 Oct 2008 00:23:33 GMT} last-modified {Fri, 31 Oct 2008 00:18:33 GMT} location http://www.wetter.com/deutschland/werder/bliesendorf/DE0011435001.html content-length 0 date {Fri, 31 Oct 2008 00:21:07 GMT} server www-8 x-cache {MISS from webcache-4.wetter.com} x-cache-lo
Code: Select all
package require http
bind pub - !wetter L:wetter
proc L:wetter {nick host hand chan arg} {
set webstring
"http://www.google.de/ig/api?weather=[lrange $arg 0 end]"
catch {exec wget -O scripts/wetter.data $webstring} err
set fp [open
"scripts/wetter.data" r]; set wetterdata [read $fp]; close $fp
regexp {(?i)<city data=\"(.*?)\"/>} $wetterdata -> wetter(stadt)
regexp
{(?i)<postal_code data=\"(.*?)\"/>} $wetterdata -> wetter(plz)
regexp {(?i)temp_c data=\"(.*?)\"/>} $wetterdata -> wetter(current_celsius)
regexp {(?i)humidity data=\"(.*?)\"/>} $wetterdata -> wetter(current_feuchtigkeit)
regexp {(?i)wind_condition data=\"(.*?)\"/>} $wetterdata
-> wetter(current_wind)
regexp {(?i)condition data=\"(.*?)\"/>} $wetterdata -> wetter(current_weather)
if {$wetter(current_weather) == ""} {
set wetter(current_weather) "Aktuelle Wetterlage unklar" }
putserv "privmsg $chan :Wetter für $wetter(stadt) \($wetter(plz)\) - Temp:
$wetter(current_celsius) °C - $wetter(current_wind) - $wetter(current_feuchtigkeit) - $wetter(current_weather) - Mehr Wetter: \002www.wetter.ozon.nu\002 "
}
putlog "GoogleWeather loaded"
Code: Select all
# wetter.tcl for eggdrop 1.0-alpha1 version by alexex
# Copyright (C) 2009 alexex
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any
# later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program; if not, see
# http://www.gnu.org/licenses/ .
# wetter script für deutschland, österreich & schweiz
namespace eval wetter {
# With this variable you can change the command on which the weather is gonna be checked.
variable bind "?wetter"
package require http
package require Tcl 8.5
http::config -useragent "Mozilla/5.0 (compatible; Konqueror/4.3; Linux) KHTML/4.3.2 (like Gecko)"
# Gets id of the most likely place for input, if it returns 0, nothing was found.
proc place {input} {
set url "http://www.wetter.com/suche/?search=[http::formatQuery $input]"
set token [http::geturl $url]
upvar #0 $token state
set i [lsearch $state(meta) "Location"]
if {$i == -1} {
set data [http::data $token]
if {![regexp {<a class="search_result" href="http://www.wetter.com/deutschland/.*?/(.*?).html" target="_top">} $data -> id]} {
set id 0
}
} else {
incr i
regexp {.*/(.*?).html} [lindex $state(meta) $i] -> id
}
return $id
}
# Checks for weather for place on day, where place is the return of place, and day, is either today, tomorrow or count of days.
proc check {place day} {
set url "http://www.wetter.com/wetter_aktuell/wettervorhersage/16_tagesvorhersage/?id=$place"
set data [http::data [http::geturl $url]]
switch $day {
"today" {set day [clock format [clock seconds] -format %A -locale de_DE]}
"tomorrow" {set day [clock format [clock add [clock seconds] 1 days] -format %A -locale de_DE]}
default {
if {![string is digit $day] || $day > 11 || $day < 0} {set day 0}
set day [clock format [clock add [clock seconds] $day days] -format %A -locale de_DE]
}
}
regexp [subst -nocommands {<td class="fc_title fc_center">.*?$day.*?<td class="fc_sub_title fc_center">(.*?)</td>.*?<span class="temp">(.*?)</span>}] $data -> mood temp
set mood [string trim $mood [list " " " " \n]]
return [list $mood $temp]
}
bind pub - $bind [namespace current]::pub
proc pub {nick uhost handle channel text} {
# TODO: Check when its needed and initialize it then.
variable bind
if {[llength $text] == 0} {
putserv "PRIVMSG $channel :Das war ein bisschen zu wenig Info $nick, wie wärs mit '$bind <ort/plz>'?"
return 0
} elseif {[llength $text] == 1} {
set day 0
set out "heute"
set place $text
} else {
set last [lindex $text end]
if {[string equal $last "heute"]} {
set day 0
set out "heute"
set place [join [lrange [split $text] 0 end-1]]
} elseif {[string equal $last "morgen"]} {
set day 1
set out "morgen"
set place [join [lrange [split $text] 0 end-1]]
} elseif {[string is integer $last]} {
if {$last < 0 || $last > 10} {
putserv "PRIVMSG $channel :Soweit kann ich nicht in die Zukunft/Vergangenheit schauen, versuchs mal mit einer Zahl zwischen 0 und 10 $nick."
return 0
} else {
set day $last
set out "in $day Tagen"
set place [join [lrange [split $text] 0 end-1]]
}
} else {
set place $text
set day 0
set out "heute"
}
}
if {[set id [place $place]] == 0} {
putserv "PRIVMSG $channel :Tut mir leid $nick, zu deiner Suche nach '$place' wurde nichts gefunden. Versuchs mal mit was anderem."
return 0
} else {
set forecast [check $id $day]
putserv "PRIVMSG $channel :$nick: $out wird das Wetter in $place [lindex $forecast 0] bei [lindex $forecast 1]° Celsius."
return 1
}
}
}