mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
finance-quote-wrapper - implement check and fetch in one file via command line switches
This obsoletes gnc-fq-check as the same function can now be performed with 'finance-quote-wrapper -v'
This commit is contained in:
parent
8c08fedaa1
commit
bf357315fd
@ -119,8 +119,8 @@ GncQuotesImpl::check (QofBook *book)
|
|||||||
m_dflt_curr = gnc_default_currency();
|
m_dflt_curr = gnc_default_currency();
|
||||||
|
|
||||||
auto perl_executable = bp::search_path("perl");
|
auto perl_executable = bp::search_path("perl");
|
||||||
auto fq_check = std::string(gnc_path_get_bindir()) + "/gnc-fq-check";
|
auto fq_wrapper = std::string(gnc_path_get_bindir()) + "/finance-quote-wrapper";
|
||||||
StrVec args { "-w", fq_check };
|
StrVec args { "-w", fq_wrapper, "-v" };
|
||||||
|
|
||||||
auto cmd_out = run_cmd (perl_executable.string(), args, StrVec());
|
auto cmd_out = run_cmd (perl_executable.string(), args, StrVec());
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ GncQuotesImpl::fetch (const CommVec& commodities)
|
|||||||
|
|
||||||
auto perl_executable = bp::search_path("perl");
|
auto perl_executable = bp::search_path("perl");
|
||||||
auto fq_wrapper = std::string(gnc_path_get_bindir()) + "/finance-quote-wrapper";
|
auto fq_wrapper = std::string(gnc_path_get_bindir()) + "/finance-quote-wrapper";
|
||||||
StrVec args { "-w", fq_wrapper };
|
StrVec args { "-w", fq_wrapper, "-f" };
|
||||||
|
|
||||||
auto cmd_out = run_cmd (perl_executable.string(), args, result.str());
|
auto cmd_out = run_cmd (perl_executable.string(), args, result.str());
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ non-zero - failure
|
|||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub check_modules {
|
sub check_modules {
|
||||||
my @modules = qw(Finance::Quote JSON::Parse);
|
my @modules = qw(Finance::Quote JSON::Parse Getopt::Std);
|
||||||
my @missing;
|
my @missing;
|
||||||
|
|
||||||
foreach my $mod (@modules) {
|
foreach my $mod (@modules) {
|
||||||
@ -101,6 +101,26 @@ sub check_modules {
|
|||||||
exit 1;
|
exit 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub print_version {
|
||||||
|
my $quoter = Finance::Quote->new();
|
||||||
|
my @sources = $quoter->sources();
|
||||||
|
print "$Finance::Quote::VERSION\n";
|
||||||
|
foreach my $source (@sources) {
|
||||||
|
print "$source\n";
|
||||||
|
}
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub print_usage {
|
||||||
|
print STDERR
|
||||||
|
"Usage:
|
||||||
|
Check proper installation and version:
|
||||||
|
finance-quote-wrapper -v
|
||||||
|
Fetch quotes (input should be passed as JSON via stdin):
|
||||||
|
finance-quote-wrapper -f
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
sub sanitize_hash {
|
sub sanitize_hash {
|
||||||
|
|
||||||
my (%quotehash) = @_;
|
my (%quotehash) = @_;
|
||||||
@ -160,6 +180,30 @@ sub parse_commodities {
|
|||||||
|
|
||||||
# Check for and load non-standard modules
|
# Check for and load non-standard modules
|
||||||
check_modules ();
|
check_modules ();
|
||||||
|
|
||||||
|
my %opts;
|
||||||
|
my $status = getopts('hvf', \%opts);
|
||||||
|
if (!$status)
|
||||||
|
{
|
||||||
|
print_usage();
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists $opts{'v'})
|
||||||
|
{
|
||||||
|
print_version();
|
||||||
|
}
|
||||||
|
elsif (exists $opts{'h'})
|
||||||
|
{
|
||||||
|
print_usage();
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
elsif (!exists $opts{'f'})
|
||||||
|
{
|
||||||
|
print_usage();
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
JSON::Parse->import(qw(valid_json parse_json));
|
JSON::Parse->import(qw(valid_json parse_json));
|
||||||
|
|
||||||
my $json_input = do { local $/; <STDIN> };
|
my $json_input = do { local $/; <STDIN> };
|
||||||
|
Loading…
Reference in New Issue
Block a user