mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Better error reporting. Don't uppercase the symbol name.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10944 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
1d4bc05065
commit
af7a01368e
@ -48,27 +48,51 @@ sub check_modules {
|
||||
sub report {
|
||||
my($itemname, $qh, $verbose) = @_;
|
||||
my ($symbol, $date, $currency, $last, $nav, $price, $timezone, $keyname);
|
||||
my($success);
|
||||
my($gccanuse);
|
||||
|
||||
# Sanity check returned results
|
||||
if ((keys %$qh) < 1) {
|
||||
printf("No results found for stock $itemname.\n");
|
||||
return;
|
||||
} else {
|
||||
my ($stock, $attribute, %seen, $first);
|
||||
|
||||
foreach $keyname (sort keys %$qh) {
|
||||
($stock, $attribute) = split('\034', $keyname);
|
||||
last if $stock eq $itemname;
|
||||
$first = $stock if !defined $first;
|
||||
$seen{$stock} = 1;
|
||||
}
|
||||
|
||||
if ($stock ne $itemname) {
|
||||
printf "\nNo results found for stock $itemname, but results were returned for\n";
|
||||
printf "the stock(s) %s. ", join(", ", keys(%seen));
|
||||
printf "Printing data for the first stock returned.\n\n";
|
||||
|
||||
# Print stats for the first stock returned.
|
||||
$itemname = $first;
|
||||
}
|
||||
}
|
||||
|
||||
# Parse the quote fields and put warnings where necessary.
|
||||
$success = 1;
|
||||
$gccanuse = 1;
|
||||
if (defined($$qh{$itemname, "symbol"})) {
|
||||
$symbol = $$qh{$itemname, "symbol"};
|
||||
} else {
|
||||
$symbol = "$itemname (deduced)";
|
||||
$success = 0;
|
||||
$gccanuse = 0;
|
||||
}
|
||||
if (defined($$qh{$itemname, "date"})) {
|
||||
$date = $$qh{$itemname, "date"};
|
||||
} else {
|
||||
$date = "** missing **";
|
||||
$success = 0;
|
||||
$gccanuse = 0;
|
||||
}
|
||||
if (defined($$qh{$itemname, "currency"})) {
|
||||
$currency = $$qh{$itemname, "currency"};
|
||||
} else {
|
||||
$currency = "** missing **";
|
||||
$success = 0;
|
||||
$gccanuse = 0;
|
||||
}
|
||||
if ((!defined($$qh{$itemname, "last"})) &&
|
||||
(!defined($$qh{$itemname, "nav" })) &&
|
||||
@ -76,7 +100,7 @@ sub report {
|
||||
$$qh{$itemname, "last"} = "**missing**";
|
||||
$$qh{$itemname, "nav"} = "**missing**";
|
||||
$$qh{$itemname, "price"} = "**missing**";
|
||||
$success = 0;
|
||||
$gccanuse = 0;
|
||||
} else {
|
||||
$last = defined($$qh{$itemname, "last"})
|
||||
? $$qh{$itemname, "last"} : "";
|
||||
@ -88,20 +112,6 @@ sub report {
|
||||
$timezone = defined($$qh{$itemname, "timezone"})
|
||||
? $$qh{$itemname, "timezone"} : "";
|
||||
|
||||
# Report failure
|
||||
if ($success == 0) {
|
||||
my ($stock, $key, %seen);
|
||||
printf("\nThe query for $itemname failed!!");
|
||||
foreach $keyname (sort keys %$qh) {
|
||||
($stock, $key) = split('\034', $keyname);
|
||||
next if $stock eq $itemname;
|
||||
next if $seen{$stock} == 1;
|
||||
$seen{$stock} = 1;
|
||||
printf " Found data for stock(s) %s instead.\n", join(", ", keys(%seen));
|
||||
}
|
||||
printf "\n";
|
||||
}
|
||||
|
||||
# Dump gnucash recognized fields
|
||||
printf "Finance::Quote fields Gnucash uses:\n";
|
||||
printf " symbol: %-20s <=== required\n", $symbol;
|
||||
@ -112,6 +122,11 @@ sub report {
|
||||
printf " price: %-20s <=/ \n", $price;
|
||||
printf " timezone: %-20s <=== optional\n", $timezone;
|
||||
|
||||
# Report failure
|
||||
if ($gccanuse == 0) {
|
||||
printf "\n** This stock quote cannot be used by gnucash!!\n\n";
|
||||
}
|
||||
|
||||
# Dump all fields if requested
|
||||
if ($verbose) {
|
||||
printf "\nAll fields returned by Finance::Quote for stock $itemname\n\n";
|
||||
@ -148,7 +163,6 @@ my $exchange = shift;
|
||||
while ($#ARGV >= 0) {
|
||||
my $stock = shift;
|
||||
my %quotes = $q->fetch($exchange, $stock);
|
||||
$stock =~ tr/a-z/A-Z/;
|
||||
report($stock, \%quotes, $verbose);
|
||||
if ($#ARGV >= 0) {
|
||||
printf "=====\n\n";
|
||||
|
Loading…
Reference in New Issue
Block a user