Created
September 27, 2012 02:06
-
-
Save tatsuyaueda/3791764 to your computer and use it in GitHub Desktop.
Ene Repo Power usage information acquisition Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
use strict; | |
use warnings; | |
use HTTP::Request::Common; | |
use LWP::UserAgent; | |
use DateTime; | |
my $cookie_file = "cookies.txt"; | |
my $url = "https://ene.tokai.jp/loginform.asp?csd=0"; | |
my $id = ""; | |
my $pass = ""; | |
my $debug = 0; | |
######################################## | |
my $dt = DateTime->now( time_zone=>'local' ); | |
$dt->subtract(days => 1); | |
my $request = POST($url, [id => $id, pw => $pass]); | |
my $ua = LWP::UserAgent->new(); | |
$ua->cookie_jar({file =>$cookie_file, autosave=>1 }); | |
$ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; ja)"); | |
my $res = $ua->request($request); | |
if($debug){ | |
print "========== Auth Request Meesage =========="; | |
print $request->as_string; | |
print "========== Auth Response Meesage =========="; | |
print $res->as_string; | |
} | |
$request = GET("https://ene.tokai.jp/mypage/graph-day.asp?date=" . $dt->strftime('%Y%m%d')); | |
$res = $ua->request($request); | |
if($debug){ | |
print "========== DataGet Request Meesage =========="; | |
print $request->as_string; | |
print "========== DataGet Response Meesage =========="; | |
print $res->as_string; | |
} | |
my @lines = split(/\r\n/, $res->as_string); | |
my $DataLine; | |
for(my $i = 0; $i < $#lines; $i++){ | |
if($lines[$i] =~/series: \[/){ | |
$DataLine = $i; | |
last; | |
} | |
} | |
$DataLine++; | |
print $lines[$DataLine]; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment