added config file logic
This commit is contained in:
parent
3baf40e13b
commit
65a731a71b
|
@ -0,0 +1 @@
|
|||
tibber.conf
|
|
@ -0,0 +1 @@
|
|||
token = TOKENTOKEN
|
15
tibber.pl
15
tibber.pl
|
@ -3,12 +3,25 @@ use 5.024;
|
|||
use strict;
|
||||
use warnings;
|
||||
use autodie;
|
||||
use Config::Tiny;
|
||||
use Getopt::Long;
|
||||
use HTTP::Tiny;
|
||||
use JSON::PP;
|
||||
use Data::Dumper;
|
||||
|
||||
my $TOKEN = "";
|
||||
GetOptions(
|
||||
"config=s" => \(my $CONFIG),
|
||||
);
|
||||
|
||||
my $USAGE = <<"END_USAGE";
|
||||
Usage: $0 [-c config]
|
||||
Options:
|
||||
-c | --config text (no default)
|
||||
END_USAGE
|
||||
|
||||
my @config_files = $CONFIG || grep { -e } ('./_tibber.conf', './.tibber.conf', './tibber.conf', "$ENV{'HOME'}/_tibber.conf", "$ENV{'HOME'}/.tibber.conf", "$ENV{'HOME'}/tibber.conf");
|
||||
my $config = Config::Tiny->read($config_files[-1], 'utf8');
|
||||
my $TOKEN = $config->{$APPLICATION}->{token} || die("$USAGE\nError: TOKEN not found.\n");
|
||||
|
||||
my $http = HTTP::Tiny->new;
|
||||
my %HEADERS = ("Content-Type" => "application/json", "Authorization" => "Bearer $TOKEN");
|
||||
|
|
Loading…
Reference in New Issue