Skip to content

Instantly share code, notes, and snippets.

@nkmrgk
Created March 29, 2011 15:19
Show Gist options
  • Save nkmrgk/892541 to your computer and use it in GitHub Desktop.
Save nkmrgk/892541 to your computer and use it in GitHub Desktop.
tepco-epu.pl for developer.yahoo.co.jp
#!/usr/bin/env perl
use strict;
use warnings;
use WebService::Simple;
use File::Find::Rule;
my $appid = 'your-appid-of-developer.yahoo.co.jp';
my $myname = 'tepco-epu';
my $base_url = 'http://setsuden.yahooapis.jp/v1/Setsuden/latestPowerUsage';
my $service = WebService::Simple->new(
base_url => $base_url,
response_parser => 'JSON',
);
my $res = $service->get({
appid => $appid,
output => 'json'
});
my $ref = $res->parse_response;
my $epu = $ref->{ElectricPowerUsage};
my $usage = $epu->{Usage}->{'$'} / 10000;
my $capa = $epu->{Capacity}->{'$'} / 10000;
my $ratio = int(($epu->{Usage}->{'$'} / $epu->{Capacity}->{'$'}) * 100);
use Win32;
my $dirname = "$ratio% $usage of $capa". "kW $myname";
my $desktop = Win32::GetFolderPath(Win32::CSIDL_DESKTOP);
my @dirs = File::Find::Rule->name('*'.$myname)->maxdepth(1)->in($desktop);
my $oldpath = ($dirs[0] and -d $dirs[0]) ? $dirs[0] :
File::Spec->catfile($desktop, $dirname);
my $newpath = File::Spec->catfile($desktop, $dirname);
mkdir $newpath if (!-d $oldpath);
rename $oldpath, $newpath if (-d $oldpath);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment