Code Sample |
$ zdump EST |
Code Sample |
#!/usr/bin/perl # Use -h for useage # 24-hour, multi arg version # -f option for long city listing # -w option to set output width use strict; use warnings; use Getopt::Std; my $defaultwidth = 14; # default output width in chars, overidden by -w switch #======================================== sub twelveto24{ # adapted from http://keithdevens.com/weblog/archive/2006/Feb/02/12-to-24 my ($hr, $per) = @_; return '00' if($hr == 12 and $per eq 'AM'); return $hr+12 if($hr != 12 and $per eq 'PM'); if (length($hr) eq 1){ $hr = '0' . $hr }; return $hr; } #========================================= my ($city, $URL, $displaywidth); our ($opt_f, $opt_h, $opt_w); my $download = "/tmp/citytimes.$$.html"; # Parse cli switches getopts('fhw:'); if ($opt_h) { die "Useage: $0 [-f|-h] [-w WIDTH ] somecity1 somecity2 somecity3 ..\n" }; if (!$ARGV[0]) {die "No city specified"}; if ($opt_w){ if ($opt_w !~ /\d+/ ) { die "Invalid argument to -w option" } else { $displaywidth = $opt_w } } else { $displaywidth = $defaultwidth } #~ if ($opt_f) { $URL = "http://www.timeanddate.com/worldclock/full.html" #~ } else { $URL = "http://www.timeanddate.com/worldclock/" } if ($opt_f) { $URL = "http://www.whattimeisit.com/cgitime.exe?Mode=FullList" } else { $URL = "http://www.whattimeisit.com/cgitime.exe?Mode=FullList" } # print "timeanddate.com:\n"; # legal print "www.whattimeisit.com:\n"; system("wget -O $download $URL &>/dev/null"); open(CONT, $download) or die "Could not open $download"; while (<CONT>){ foreach $city(@ARGV) { if ($city !~ /\w+/) { die "City '$city' not alphanumeric" } if (/$city.+?(\d{1,2})\:(\d+\d+) ((AM|PM))/i) { my ($hr, $min, $ampm) = ( $1, $2, $3); my $newhr = twelveto24($hr, $ampm); my $newtime = $newhr . ":" . $min; my $F = 'A' . $displaywidth; print pack("$F A5", $city, $newtime), "\n"; } } } unlink $download; |
Code Sample |
$ /opt/citytime.pl tokyo paris houston Downloading time from http://www.timeanddate.com/worldclock/ tokyo 2:33 paris 19:33 houston 12:33 |
Code Sample |
${color red}$hr ${color grey}Tokyo: $color ${execi 180 ~/.citytime.pl Tokyo} |
Quote |
Tokyo: Getting time from http://www.timeanddate.com/worldclock |