added config file logic

This commit is contained in:
mischa 2023-09-24 12:59:55 +00:00
parent 3baf40e13b
commit 65a731a71b
3 changed files with 16 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
tibber.conf

1
tibber.conf-sample Normal file
View File

@ -0,0 +1 @@
token = TOKENTOKEN

View File

@ -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");