Advertisement
Ford

Wunderground weather tcl with german translations by Greyman

Sep 8th, 2013
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 11.00 KB | None | 0 0
  1. ##############################################################################################
  2. # wunderground.tcl German version for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help#
  3. ##############################################################################################
  4. ## To use this script you must set channel flag +weather (ie .chanset #chan +weather)       ##
  5. ##############################################################################################
  6. ##############################################################################################
  7. ##  ##                             Start Setup.                                         ##  ##
  8. ##############################################################################################
  9. namespace eval wunderground {
  10. ## Change forc to force temp results of F or C.                                         ##  ##
  11.   variable forc "C"
  12. ## Edit logo to change the logo displayed at the start of the line                      ##  ##
  13.   variable logo "\017\00304\002W\00304u\00307n\00308d\00311e\00312r\00304g\00307r\00308o\00311u\00312n\00304d\017"
  14. ## Edit textf to change the color/state of the text shown                               ##  ##
  15.   variable textf "\017\00304"
  16. ## Edit tagf to change the color/state of the Tags:                                     ##  ##
  17.   variable tagf "\017\002"
  18. ## Edit weatherline, line1, line2, line3, line4 to change what is displayed             ##  ##
  19. ## weatherline is for the !weather trigger and line1-4 are for !forecast                ##  ##
  20. ## Valid items are: location weatherstation conditions temperature feelslike            ##  ##
  21. ## windspeed winddirection sunset sunrise moon                                          ##  ##
  22. ## day1 day2 day3 day4 day5 day6 day7 day8 day9 day10                                   ##  ##
  23. ## Do not remove any variables here! Just change them to "" to suppress display         ##  ##
  24.   variable line1 "location weatherstation conditions temperature feelslike windspeed winddirection sunset sunrise moon"
  25.   variable line2 "day1 day2 day3 day4 day5"
  26.   variable line3 "day6 day7 day8 day9 day10"
  27.   variable line4 ""
  28.   variable weatherline "location weatherstation conditions temperature feelslike windspeed winddirection sunset sunrise moon"
  29. ## Edit cmdchar to change the !trigger used to for this script                          ##  ##
  30.   variable cmdchar "!"
  31. ##############################################################################################
  32. ##  ##                           End Setup.                                              ## ##
  33. ##############################################################################################
  34.   setudef flag weather
  35.   bind pub -|- [string trimleft $wunderground::cmdchar]weather wunderground::main
  36.   bind pub -|- [string trimleft $wunderground::cmdchar]forecast wunderground::main
  37. }
  38. proc wunderground::main {nick host hand chan text} {
  39.   if {[lsearch -exact [channel info $chan] +weather] != -1} {
  40.     set search [strip $text]; set command [string trimleft $::lastbind $wunderground::cmdchar]
  41.     set div ""; set moon ""; set sunset ""; set sunrise ""; set windspeed ""
  42.     set winddirection ""; set location ""; set weatherstation ""; set temperature ""
  43.     set conditions ""; set feelslike ""; set fconditions ""; set ftemp ""
  44.     set details ""; set forc ""; set count 1; set fconditionsfound ""
  45.     set day1 ""; set day2 ""; set day3 ""; set day4 ""; set day5 ""
  46.     set day6 ""; set day7 ""; set day8 ""; set day9 ""; set day10 ""
  47.     set wundergroundurl "/cgi-bin/findweather/hdfForecast?query=[urlencode $search]"
  48.     set wundergroundsite "deutsch.wunderground.com"
  49.     if {[catch {set wundergroundsock [socket -async $wundergroundsite 80]} sockerr]} {
  50.       return 0
  51.     } else {
  52.       puts $wundergroundsock "GET $wundergroundurl HTTP/1.0"
  53.       puts $wundergroundsock "Host: $wundergroundsite"
  54.       puts $wundergroundsock "User-Agent: Opera 9.6"
  55.       puts $wundergroundsock ""
  56.       flush $wundergroundsock
  57.       while {![eof $wundergroundsock]} {
  58.         set wundergroundvar " [gets $wundergroundsock] "
  59.         regexp -nocase {<div id="(.*?)"\s?>} $wundergroundvar match div
  60.         if {[regexp -nocase {<title>Weather\sForecast\s(.*?)\s\|} $wundergroundvar match location]} {
  61.           set location "${wunderground::tagf}Ort: ${wunderground::textf}${location}"
  62.         } elseif {[regexp -nocase {<div\sclass="b"><a href="\/weatherstation.*">(.*?)<\/a><\/div>} $wundergroundvar match weatherstation]} {
  63.           set weatherstation "${wunderground::tagf}Wetterstation: ${wunderground::textf}${weatherstation}"
  64.         } elseif {[regexp -nocase {<div\sid="curCond">(.+?)<\/div>} $wundergroundvar match conditions]} {
  65.           set conditions "${wunderground::tagf}Bedingungen: ${wunderground::textf}${conditions}"
  66.         } elseif {$div == "tempActual" && [regexp -nocase {<span\sclass="b">(.+?)<\/span>} $wundergroundvar match temperature]} {
  67.           regexp -nocase {&nbsp;&deg;(.*?)<} $wundergroundvar match forc
  68.           if {![string equal -nocase $wunderground::forc $forc] && $forc != ""} {
  69.             set temperature [forc $temperature $forc]
  70.             set forc $wunderground::forc
  71.           }
  72.           set temperature "${wunderground::tagf}Temperatur: ${wunderground::textf}${temperature}º ${forc}"
  73.         } elseif {$div == "tempFeel" && [regexp -nocase {<span\sclass="b">(.+?)<\/span>} $wundergroundvar match feelslike]} {
  74.           regexp -nocase {&nbsp;&deg;(.*?)<} $wundergroundvar match forc
  75.           if {![string equal -nocase $wunderground::forc $forc] && $forc != ""} {
  76.             set feelslike [forc $feelslike $forc]
  77.             set forc $wunderground::forc
  78.           }
  79.           set feelslike "${wunderground::tagf}Gefühlte Temperatur: ${wunderground::textf}${feelslike}º ${forc}"
  80.         } elseif {$div == "windCompassContainer" && [regexp -nocase {windCompassSpeed.*>(.+)<\/span>} $wundergroundvar match windspeed]} {
  81.           set windspeed "${wunderground::tagf}Windgeschwindigkeit: ${wunderground::textf}${windspeed}"
  82.         } elseif {$div == "windCompassContainer" && [regexp -nocase {windCompass.*>(.+)<\/span>} $wundergroundvar match winddirection]} {
  83.           set winddirection "${wunderground::tagf}Windrichtung: ${wunderground::textf}${winddirection}"
  84.         } elseif {$div == "sRise" && [regexp -nocase {class="b">(.+?)<\/span>} $wundergroundvar match sunrise]} {
  85.           regexp -nocase {span>(.*?)<\/div>} $wundergroundvar match ampm
  86.           set sunrise "${wunderground::tagf}Sonnenaufgang: ${wunderground::textf}${sunrise}${ampm}"
  87.         } elseif {$div == "sSet" && [regexp -nocase {class="b">(.+?)<\/span>} $wundergroundvar match sunset]} {
  88.           regexp -nocase {span>(.*?)<\/div>} $wundergroundvar match ampm
  89.           set sunset "${wunderground::tagf}Sonnenuntergang: ${wunderground::textf}${sunset}${ampm}"
  90.         } elseif {[regexp -nocase {<div\sid="mPhase".*">(.+?)<\/div>} $wundergroundvar match moon]} {
  91.           set moon "${wunderground::tagf}Mond: ${wunderground::textf}${moon}"
  92.        } elseif {$div == "hourZZ" && $command == "weather"} {
  93.           msg $chan $wunderground::logo ${wunderground::textf} [subst [regsub -all -nocase {(\S+)} $wunderground::weatherline {$\1}]]
  94.           close $wundergroundsock
  95.           return 0
  96.         } elseif {[regexp -nocase {<div\sclass="fctDayDate">(.+)\,} $wundergroundvar match day]} {
  97.           set day "${wunderground::tagf}${day}"
  98.         } elseif {[string match "*fct_day_*" $div] && [regexp -nocase {"b">(.+?)\s&deg;} $wundergroundvar match ftemp]} {
  99.           set ftemp [striphtml $ftemp]
  100.           regexp -nocase {&deg;(.+?)} $wundergroundvar match forc
  101.           set ftemp "[string map {"| " ""} $ftemp]"
  102.           foreach {hi lo} $ftemp break
  103.           if {![string equal -nocase $wunderground::forc $forc] && $forc != ""} {
  104.             set hi [forc $hi $forc]
  105.             set lo [forc $lo $forc]
  106.             set forc $wunderground::forc
  107.           }
  108.           set ftemp "${wunderground::tagf}Temperatur: ${wunderground::textf}${hi}º|${lo}º ${forc}"
  109.         } elseif {[string match "*<div class=\"fctDayConditions\">*" $wundergroundvar]} {
  110.           set fconditionsfound "on"
  111.         } elseif {$fconditionsfound == "on"} {
  112.           regexp {(.*?)\s?$} $wundergroundvar match fconditions
  113.           set fconditions "${wunderground::tagf}Bedingung:${wunderground::textf}${fconditions}."
  114.           set fconditionsfound ""
  115.         } elseif {[string match "*fct_day_*" $div] && [regexp -nocase {popText">(.+?)<\/div} $wundergroundvar match details]} {
  116.           set details ${wunderground::textf}[string map {"<br />" " "} $details]
  117.         } elseif {[regexp -nocase {popValue">(.+?)<\/div>} $wundergroundvar match chance]} {
  118.           set details "$details $chance"
  119.           set day${count} "${day} $ftemp ${fconditions}"
  120.           incr count
  121.         } elseif {$div == "fct_details"} {
  122.           if {$wunderground::line1 != ""} {
  123.             msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line1 {$\1}]]
  124.           }
  125.           if {$wunderground::line2 != ""} {
  126.             msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line2 {$\1}]]
  127.           }
  128.           if {$wunderground::line3 != ""} {
  129.             msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line3 {$\1}]]
  130.           }
  131.           if {$wunderground::line4 != ""} {
  132.             msg $chan $wunderground::logo $wunderground::textf [subst [regsub -all -nocase {(\S+)} $wunderground::line4 {$\1}]]
  133.           }
  134.         }      
  135.       }
  136.     }
  137.   }
  138. }
  139. proc wunderground::forc {value fc} {
  140.   if {[string equal -nocase "f" $fc]} {
  141.     if {[expr {(($value - 32) * 5)} == 0]} { return 0 }
  142.     return [format "%.1f" [expr {(($value - 32) * 5) / 9}]]
  143.   } elseif {[string equal -nocase "c" $fc]} {
  144.     if {$value == 0} { return 32 }
  145.     return [format "%.1f" [expr {(($value * 9) / 5) + 32}]]
  146.   }
  147. }
  148. proc wunderground::striphtml {string} {
  149.   return [string map {&quot; \" &lt; < &rt; >} [regsub -all {(<[^<^>]*>)} $string ""]]
  150. }
  151. proc wunderground::urlencode {string} {
  152.  regsub -all {^\{|\}$} $string "" string
  153.  return [subst [regsub -nocase -all {([^a-z0-9\+])} $string {%[format %x [scan "\\&" %c]]}]]
  154. }
  155. proc wunderground::strip {text} {
  156.  regsub -all {\002|\031|\015|\037|\017|\003(\d{1,2})?(,\d{1,2})?} $text "" text
  157.    return $text
  158. }
  159. proc wunderground::msg {chan logo textf text} {
  160.  set text [textsplit $text 50]
  161.  set counter 0
  162.  while {$counter <= [llength $text]} {
  163.    if {[lindex $text $counter] != ""} {
  164.      putserv "PRIVMSG $chan :${logo} ${textf}[string map {\\\" \"} [lindex $text $counter]]"
  165.     }
  166.     incr counter
  167.   }
  168. }
  169. proc wunderground::textsplit {text limit} {
  170.   set text [split $text " "]
  171.   set tokens [llength $text]
  172.   set start 0
  173.   set return ""
  174.   while {[llength [lrange $text $start $tokens]] > $limit} {
  175.     incr tokens -1
  176.     if {[llength [lrange $text $start $tokens]] <= $limit} {
  177.       lappend return [join [lrange $text $start $tokens]]
  178.       set start [expr $tokens + 1]
  179.       set tokens [llength $text]
  180.     }
  181.   }
  182.   lappend return [join [lrange $text $start $tokens]]
  183.   return $return
  184. }
  185. putlog "\002*Loaded* \00304\002W\00304u\00307n\00308d\00311e\00312r\00304g\00307r\00308o\00311u\00312n\00304d\017 \002by \
  186. Ford_Lawnmower irc.GeekShed.net #Script-Help"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement