This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

world time / weather tcl Requests

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
i
iRoc

world time / weather tcl Requests

Post by iRoc »

hi
i need weather / time tcl like this

Code: Select all

2:57:07am / * <iRoc> !weather Dhaka
2:57:16am / * * iB0T Dhaka, Bangladesh: Partly Cloudy and 82°F(28°C)

2:40:10am / * <iRoc> !time Jessore
2:40:13am / * <iB0T> Jessore, Bangladesh: September 14, 2:40 AM BDT

Ty
T
Torrevado
Op
Posts: 101
Joined: Wed Aug 02, 2006 6:29 pm

Post by Torrevado »

You should try weather and worldtime tcl's by hm2k


Weather:

Code: Select all

# weather.tcl -- 2.0.3
#
#   Returns the current weather for the city or postcode using the iGoogle
#    API for weather.
#
# Copyright (c) 2010 HM2K
#
# Name: Weather Lookup
# Author: HM2K <irc@hm2k.org>
# License: http://www.freebsd.org/copyright/freebsd-license.html
# Link: http://www.hm2k.com/posts/weather-tcl
# Tags: weather, lookup, google, api
# Updated: 02-Jun-2010
#
###Usage
# > .wz london
# <Bot> HM2K, * Weather: London, England: Mostly Cloudy, 8ºC Humidity: 87% Wind:
#        W at 9 mph
#
###Revisions
# 2.0.3 - better requirement checking and better file header
# 2.0.2 - now returns temperature in C or F, depending on what you define.
# 2.0.1 - fixed weather.tcl $info(problem) -> $data(problem) (tnx Pixelz)
# 2.0   - a complete rewrite using google's api to gather the weather info
# 1.x   - based on a script by Ycarus
#
###Todo
# 2.1 Switch to Yahoo's Weather API

### Settings
set wz(ver) "2.0.3"; #current version of this file
set wz(lang) "en"; #language
set wz(cmd) ".wz"; #public command trigger
set wz(dcccmd) "wz"; #dcc command trigger
set wz(prefix) "* Weather:"; #output prefix
set wz(temp) "C"; # temperature scale [C/F]
set wz(output) "\002%s:\002 %s, %sº$wz(temp) %s %s"; #format for the output
set wz(problem) "Problem:";
set wz(errormsg) "Error: No information could be found for";
set wz(usage) "Usage: $wz(cmd) <city|postcode,country>";
set wz(ua) "MSIE 6.0"; #simulate a browser's user agent, ie: Mozilla
set wz(url) "http://www.google.com/ig/api"; #url

### Package Definition
package require eggdrop 1.6;  #see http://geteggdrop.com/
package require Tcl 8.2.3;    #see http://tinyurl.com/6kvu2n
if {[catch {package require html} err]} {
  putlog "[info script] error: $err";
  putlog "[info script] error: http is required, see http://wiki.tcl.tk/1475";
}
if {[catch {package require htmlparse} err]} {
  putlog "[info script] error: $err";
  putlog "[info script] error: Tcllib is required, see http://wiki.tcl.tk/12099";
}

### Binds
bind pub - $wz(cmd) pub:wz;
bind dcc -|- $wz(dcccmd) dcc:wz;

### Procedures
proc pub:wz { nick uhost handle channel arg } {
	global wz;
	set arg [split $arg];
	if {[llength $arg]==0} { putserv "NOTICE $nick :$wz(usage)"; return; }
	set result [wz:get $arg];
	putserv "PRIVMSG $channel :$nick, $wz(prefix) $result";
}

proc dcc:wz {ha idx arg} {
  global wz;
  set arg [split $arg];
	if {[llength $arg]==0} { putdcc $idx $wz(usage); return; }
	set result [wz:get $arg];
  putdcc $idx $result; 
}

proc wz:get { arg } {
  global wz;

  set query [::http::formatQuery weather $arg hl $wz(lang)];
  #set url [format $wz(url) $arg $wz(lang)];
  
  set http [::http::config -useragent $wz(ua) -urlencoding "utf-8"];
  set http [::http::geturl $wz(url)?$query];
  set data [::http::data $http];
  set data [::htmlparse::mapEscapes $data];
  #set data [wz:parse $data "forecast_information"][wz:parse $data "current_conditions"];
  
  if {[string tolower $wz(temp)] == "f"} {
    set temp "temp_f";
  } else {
    set temp "temp_c";
  }
  
  set info(city) [wz:parsedata $data city];
  set info(condition) [wz:parsedata $data condition];
  set info(temp) [wz:parsedata $data $temp];
  set info(humidity) [wz:parsedata $data humidity];
  set info(wind) [wz:parsedata $data wind_condition];
  set info(problem) [wz:parsedata $data problem_cause];
  
  if {([info exists info(problem)]) && ($info(problem) ne "")} {
    return "$wz(problem) $info(problem)";
  }
  if {([info exists info(city)]) && ($info(city) == "")} {
    return "$wz(errormsg) $arg";
  }

  return [format $wz(output) $info(city) $info(condition) $info(temp) $info(humidity) $info(wind)];
}

proc wz:parse { data arg } {
  set arg [string tolower $arg];
  set matched "";
  set result "";
  regexp "<$arg>(.+?)</$arg>" $data matched result;
  return $result;
}

proc wz:parsedata { data arg } {
  set arg [string tolower $arg];
  set matched "";
  set result "";
  regexp "<$arg data=\"(\[^\"\]+)\"/>" $data matched result;
  return $result;
}

### Loaded
putlog "weather.tcl $wz(ver) loaded";

#EOF
Worldtime:

Code: Select all

#worldtime.tcl v2.3.2 *BETA* by HM2K <irc@hm2k.org> (Updated: 25/05/10)
#@see http://www.hm2k.com/posts/worldtime-tcl

### Usage Example ###
#> .tz london
#<Bot> HM2K, The time in Westminster, London, UK is Fri Feb 13 23:31:30 2009 (GMT+1000)

### History ###
#v2.3.2 - expanded GMT offset; added curly braces for expr
#v2.3.1 - fixed memory leaks; fixed unmatched results
#v2.3   - uses Google to retreive geo and timezone information;
#         instead of the system zoneinfo database, which was unreliable.
#         more portable, works on any platform, including Windows.
#v2.2.3 - added timezone offset to output string
#v2.2.2 - added time offset, for a bizarre situation
#v2.2.1 - a few bug fixes, now finds correct zoneinfo dir
#v2.2   - replaced old TIME method with HTP method
#v2.1   - now uses the TIME protocol to get accurate unixtime
#v2.0   - new and improved, using system zoneinfo
#v1.3   - based on a script by Murf, using worldtimeserver.com

### Settings ###
set tz(ver) "2.3.2 *BETA*"; # current version of this file
set tz(cmd) ".tz"; # public command trigger
set tz(dcccmd) "tz"; # dcc command trigger
set tz(output) "The time in \002%s\002 is %s (%s)"; # format for the output
set tz(dateformat) "%a %b %d %I:%M:%S %p %Y"; # format for the clock (wiki.tcl.tk/1810)
set tz(usage) "Usage: $tz(cmd) <location>"; # usage result
set tz(noresult) "Unable to find a match."; # no result result
set tz(gettime) 1; # when on, will get time from time server, instead of system
set tz(timeserver) "www.google.com"; # should be any good remote web server
set tz(offset) 0; # seconds, eg: 3600 for plus 1 hour or -3600 for minus
set tz(utc) "GMT"; # name given to UTC
set tz(geourl) "http://maps.google.com/maps/api/geocode/xml"; # url for Google GeoCode lookup
set tz(tzurl) "http://www.google.com/ig/timezone"; # url for Google's TimeZone lookup

### Required Packages ###
package require eggdrop 1.6;  #see http://geteggdrop.com/
package require Tcl 8.2.3;    #see http://tinyurl.com/6kvu2n
package require http;         #see http://tinyurl.com/38ma4re
if {[catch {package require htmlparse} err]} {
  putlog "[info script] error: $error";
  putlog "[info script] error: Tcllib is required, see http://tcllib.sf.net/";
}

### Binds ###
bind pub - $tz(cmd) pub:tz;
bind dcc -|- $tz(dcccmd) dcc:tz;

### Public Functions ###
proc pub:tz { nick uhost handle channel arg } {
	global tz;
	if {[llength $arg]==0} { putserv "NOTICE $nick :$tz(usage)"; return; }
	set result [tz:get $arg];
	if {$result eq ""} { set result $tz(noresult); }
	putserv "PRIVMSG $channel :$nick, $result";
}

### DCC Functions ###
proc dcc:tz {ha idx arg} {
  global tz;
	if {[llength $arg]==0} { putdcc $idx $tz(usage); return; }
	set result [tz:get $arg];
	if {$result eq ""} { set result $tz(noresult); }
  putdcc $idx $result; 
}

### Functions ###
proc tz:get { arg } {
  global tz;
  
  #set the time
  set time "";
  if {$tz(gettime)} { set time [tz:gethtp $tz(timeserver)]; }
  if {$time eq ""} { set time [clock seconds]; }
  
  #offset place holder
  set offset 0;

  #set geo location info
  set geoinfo [tz:getgeo $arg];
  
  #no results
  if {$geoinfo eq {}} { return; }

  #set timezone name
  set arg [lrange $geoinfo 2 end];

  #set timezone info
  set tzinfo [tz:gettz [lrange $geoinfo 0 1]];

  #no results
  if {$tzinfo eq {}} { return; }
  
  #get gmt offset in seconds (including dst)
  set offset [expr {[lindex $tzinfo 0]+[lindex $tzinfo 1]}];
  
  #add timezone data to current gmt time (+offset)
  set time [expr {$time+$offset/1000+$tz(offset)}];

  #format the unixtime seconds to human readable time
  set time [clock format $time -format $tz(dateformat)];
  
  #make offset human readable
  set offset [expr {$offset/3600}];
  if {$offset == 0} { set offset "$tz(utc)"; } elseif {$offset > 0} { set offset "$tz(utc)+$offset"; } else { set offset "$tz(utc)$offset"; }

  #format and return
  return [format $tz(output) $arg $time $offset];
}
proc tz:gethtp {args} { #?server? ?port?
  if {[llength $args] > 0} { set server [lindex $args 0]; } else { set server "www.google.com"; }
  if {[llength $args] > 1} { set port [lindex $args 1]; } else { set port 80; }
  set s [socket $server $port];
  puts $s "HEAD / HTTP/1.0\n";
  flush $s;
  while {[gets $s l] >= 0} {
    if {[regexp {Date: (.+?) GMT$} $l -> date]} {
      close $s;
      return [clock scan $date];
    }
  }
}
proc tz:getdata { arg } {
  if {[string length $arg]<1} { return; }
  set http [::http::geturl $arg];
  set data [::http::data $http];
  set data [::htmlparse::mapEscapes $data];
  set data [string trim $data];
  set data [join $data " "];
  ::http::cleanup $http;
  return $data;
}
proc tz:xmlparse { data arg } {
  if {[string length $arg]<1} { return; }
  set arg [string tolower $arg];
  set matched "";
  set result "";
  regexp "<$arg>(.+?)</$arg>" $data matched result;
  return $result;
}
proc tz:jsonparse { data arg } {
  if {[string length $arg]<1} { return; }
  set matched "";
  set result "";
  regexp "'$arg':(\[^,\}\]+)" $data matched result;
  return $result;
}
proc tz:getgeo { arg } {
  global tz;
  set arg [::http::formatQuery address $arg sensor "false"];
  set data [tz:getdata $tz(geourl)?$arg];
  if {[regexp "<html>.+" $data]} { return; }
  if {$data eq {}} { return; }
  #parse info
  set info(lat) [tz:xmlparse $data "lat"];
  set info(lng) [tz:xmlparse $data "lng"];
  set info(addr) [tz:xmlparse $data "formatted_address"];
  return "$info(lat) $info(lng) $info(addr)";
}
proc tz:gettz { arg } {
  global tz;
  if {[string length $arg]<1} { return; }
  set arg [::http::formatQuery lat [lindex $arg 0] lng [lindex $arg 1]];
  set data [tz:getdata $tz(tzurl)?$arg];
  if {[regexp "<html>.+" $data]} { return; }
  if {$data eq {}} { return; }
  set info(offset) [tz:jsonparse $data "rawOffset"];
  set info(dst) [tz:jsonparse $data "dstOffset"];
  return "$info(offset) $info(dst)";
}

### Loaded ###
putlog "worldtime.tcl $tz(ver) loaded"

#EOF
Post Reply