This file is indexed.

/usr/bin/gnc-fq-dump is in gnucash 1:2.6.15-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/perl
#
#    Copyright (C) 2003, David Hampton <hampton@employees.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
#    02110-1301, USA.
#

use strict;

sub check_modules {
  my @modules = qw(Finance::Quote);
  my @missing;

  foreach my $mod (@modules) {
    if (eval "require $mod") {
      $mod->import();
    }
    else {
      push (@missing, $mod);
    }
  }

  return unless @missing;

  print STDERR "$0 cannot find all the Perl modules needed to run.\n";
  print STDERR "You need to install the following Perl modules:\n";
  foreach my $mod (@missing) {
    print STDERR "  ".$mod."\n";
  }
  print STDERR "Use your system's package manager to install them,\n";
  print STDERR "or run 'gnc-fq-update' as root.\n";

  exit 1;
}

sub report {
  my($itemname, $qh, $verbose) = @_;
  my ($symbol, $date, $currency, $last, $nav, $price, $timezone, $keyname);
  my($gccanuse, $gcshoulduse) = (1, 1);

  # 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.
  if (defined($$qh{$itemname, "symbol"})) {
    $symbol = $$qh{$itemname, "symbol"};
  } else {
    $symbol = "$itemname (deduced)";
    $gccanuse = 0;
  }
  if (defined($$qh{$itemname, "date"})) {
    $date = $$qh{$itemname, "date"};
  } else {
    $date = "** missing **";
    $gcshoulduse = 0;
  }
  if (defined($$qh{$itemname, "currency"})) {
    $currency = $$qh{$itemname, "currency"};
  } else {
    $currency = "** missing **";
    $gccanuse = 0;
  }
  if ((!defined($$qh{$itemname, "last"})) &&
      (!defined($$qh{$itemname, "nav" })) &&
      (!defined($$qh{$itemname, "price"}))) {
    $$qh{$itemname, "last"} = "**missing**";
    $$qh{$itemname, "nav"} = "**missing**";
    $$qh{$itemname, "price"} = "**missing**";
    $gccanuse = 0;
  } else {
    $last = defined($$qh{$itemname, "last"})
      ? $$qh{$itemname, "last"} :  "";
    $nav = defined($$qh{$itemname, "nav"})
      ? $$qh{$itemname, "nav"} :  "";
    $price = defined($$qh{$itemname, "price"})
      ? $$qh{$itemname, "price"} :  "";
  }
  $timezone = defined($$qh{$itemname, "timezone"})
    ? $$qh{$itemname, "timezone"} :  "";

  # Dump gnucash recognized fields
  printf "Finance::Quote fields Gnucash uses:\n";
  printf "    symbol: %-20s <=== required\n",	  $symbol;
  printf "      date: %-20s <=== recommended\n",  $date;
  printf "  currency: %-20s <=== required\n", 	  $currency;
  printf "      last: %-20s <=\\       \n",    	  $last;
  printf "       nav: %-20s <=== one of these\n", $nav;
  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";
  } elsif ($gcshoulduse == 0) {
      printf "\n** This quote will have today's date, which might be incorrect.\n";
      printf "   GnuCash will use it, but you might prefer that it doesn't.\n\n";
  }
  # Dump all fields if requested
  if ($verbose) {
    printf "\nAll fields returned by Finance::Quote for stock $itemname\n\n";
    printf "%-10s %10s  %s\n", "stock", "field", "value";
    printf "%-10s %10s  %s\n", "-----", "-----", "-----";
    foreach $keyname (sort keys %$qh) {
      my ($stock, $key) = split('\034', $keyname);
      printf "%-10s %10s: %s\n", $stock, $key, $$qh{$stock, $key};
    }
    print "\n";
  }
}

# Check for and load non-standard modules
check_modules ();

my $q = Finance::Quote->new;
$q->timeout(60);

if ($#ARGV < 1) {
  my @sources = $q->sources();
  printf "\nUsage: $0 <quote-source> [-v] <stock> [<stock> ...]\n\n";
  printf "Available sources are: \n     %s\n\n", join(' ', @sources);
  exit 0;
}

my $verbose = 0;
if (@ARGV[0] eq "-v") {
  $verbose = 1;
  shift;
}

my $exchange = shift;
if ($exchange eq "currency") {
  my $from = shift;
  while ($#ARGV >= 0) {
    my $to = shift;
    my $result = $q->currency($from, $to);
    if (defined($result)) {
      printf "1 $from = $result $to\n";
    } else {
      printf "1 $from = <unknown> $to\n";
    }
  }
} else {
  while ($#ARGV >= 0) {
    my $stock = shift;
    my %quotes = $q->fetch($exchange, $stock);
    report($stock, \%quotes, $verbose);
    if ($#ARGV >= 0) {
      printf "=====\n\n";
    }
  }
}

=head1 NAME

gnc-fq-dump	- Print out data from the F::Q module

=head1 SYNOPSIS

    gnc-fq-dump yahoo CSCO JNPR
    gnc-fq-dump yahoo BAESY.PK
    gnc-fq-dump europe 48406.PA 13000.PA
    gnc-fq-dump vwd 632034
    gnc-fq-dump ftportfolios FKYGTX

=head1 DESCRIPTION

This program obtains information from Finance::Quote about any
specified stock, and then dumps it to the screen in annotated form.
This will allow someone to see what is returned, and whether it
provides all the information needed by Gnucash.

=cut