Initial commit
This commit is contained in:
commit
3baf40e13b
51
tibber.pl
Executable file
51
tibber.pl
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
use 5.024;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use autodie;
|
||||||
|
use Getopt::Long;
|
||||||
|
use HTTP::Tiny;
|
||||||
|
use JSON::PP;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
my $TOKEN = "";
|
||||||
|
|
||||||
|
my $http = HTTP::Tiny->new;
|
||||||
|
my %HEADERS = ("Content-Type" => "application/json", "Authorization" => "Bearer $TOKEN");
|
||||||
|
my $uri = "https://api.tibber.com/v1-beta/gql";
|
||||||
|
|
||||||
|
my $request = HTTP::Tiny->new('default_headers' => \%HEADERS);
|
||||||
|
my $json = JSON::PP->new;
|
||||||
|
|
||||||
|
my $body = $json->encode({query => "{viewer{homes{currentSubscription{priceInfo{current{total energy tax startsAt} today{total energy tax startsAt} tomorrow{total energy tax startsAt}}}}}}"});
|
||||||
|
#print "$body\n";
|
||||||
|
|
||||||
|
my $response = $request->post($uri, {'content' => $body});
|
||||||
|
#print "$response->{'status'} $response->{'reason'}\n";
|
||||||
|
#print "$response->{'content'}\n";
|
||||||
|
my $data = $json->decode($response->{'content'})->{'data'}->{'viewer'}->{'homes'}[0]->{'currentSubscription'};
|
||||||
|
|
||||||
|
print "*** priceInfo ***\n";
|
||||||
|
print "current: ";
|
||||||
|
if (!length $data->{'priceInfo'}->{'current'}) {
|
||||||
|
print "price not set\n";
|
||||||
|
} else {
|
||||||
|
print "$data->{'priceInfo'}->{'current'}->{'total'} (Energy: $data->{'priceInfo'}->{'current'}->{'energy'}; Tax: $data->{'priceInfo'}->{'current'}->{'tax'})\n";
|
||||||
|
#print Dumper $data->{'priceInfo'}->{'current'};
|
||||||
|
}
|
||||||
|
|
||||||
|
print "today: ";
|
||||||
|
if (!length $data->{'priceInfo'}->{'today'}[0]) {
|
||||||
|
print "price not set\n";
|
||||||
|
} else {
|
||||||
|
print "$data->{'priceInfo'}->{'today'}[0]->{'total'} (Energy: $data->{'priceInfo'}->{'today'}[0]->{'energy'}; Tax: $data->{'priceInfo'}->{'today'}[0]->{'tax'})\n";
|
||||||
|
#print Dumper $data->{'priceInfo'}->{'today'}[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
print "tomorrow: ";
|
||||||
|
if (!length $data->{'priceInfo'}->{'tomorrow'}[0]) {
|
||||||
|
print "price set at 13:00\n";
|
||||||
|
} else {
|
||||||
|
print "$data->{'priceInfo'}->{'tomorrow'}[0]->{'total'} (Energy: $data->{'priceInfo'}->{'tomorrow'}[0]->{'energy'}; Tax: $data->{'priceInfo'}->{'tomorrow'}[0]->{'tax'})\n";
|
||||||
|
#print Dumper $data->{'priceInfo'}->{'tomorrow'}[0];
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user