This file is indexed.

/usr/share/perl5/Finance/Quote/FTfunds.pm is in libfinance-quote-perl 1.38-1.

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

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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/usr/bin/perl -w

#  ftfunds.pm
#
#  Obtains quotes for UK Unit Trusts from http://funds.ft.com/ - please
#  refer to the end of this file for further information.
#
#  author: Martin Sadler (martinsadler@users.sourceforge.net)
#
#  Version 0.1 Initial version - 06 Sep 2010
#
#  Version 0.2 Better look-up  - 19 Sep 2010
#
#  Version 0.3 name changed to "ftfunds"
#              (all lower case) and tidy-up - 31 Jan 2011
#
#  Version 0.4 Allows alphanumerics MEXIDs
#              and back to "FTfunds"        - 28 Feb 2011
#
#  Version 1.0 Changed to work with the new
#              format of funds.ft.com       - 14 Sep 2011
#
#  Version 2.0 Changed to work with the latest
#              format of funds.ft.com		- 31 Mar 2013
#
#    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., 59 Temple Place - Suite 330, Boston, MA
#    02111-1307, USA
#


package Finance::Quote::FTfunds;
require 5.005;

use strict;
use warnings;

# Set DEBUG => 1 for no debug messages, => 1 for first level, => 2 for 2nd level, etc.

use constant DEBUG => 0;

# URLs
use vars qw($VERSION $FTFUNDS_LOOK_UD $FTFUNDS_LOOK_LD $FTFUNDS_MAIN_URL);

use LWP::UserAgent;
use HTTP::Request::Common;
use HTTP::Cookies;
use HTML::TokeParser;
# use Data::Dumper;

our $VERSION = '1.38'; # VERSION

$FTFUNDS_MAIN_URL   =   "http://funds.ft.com";
$FTFUNDS_LOOK_LD    =   "http://funds.ft.com/UK/Tearsheet/Summary?s=";
$FTFUNDS_LOOK_UD    =	"http://funds.ft.com/UnlistedTearsheet/Summary?s=";

                        # this will work with ISIN codes only.

# FIXME -

sub methods { return (ftfunds => \&ftfunds_fund,
		      ukfunds => \&ftfunds_fund); }

{
    my @labels = qw/name currency last date time price nav source iso_date method net p_change success errormsg/;

    sub labels { return (ftfunds => \@labels,
			 ukfunds => \@labels); }
}

#
# =======================================================================

sub ftfunds_fund  {
    my $quoter = shift;
    my @symbols = @_;

    return unless @symbols;

    my %fundquote;

    my $ua = $quoter->user_agent;
    my $cj = HTTP::Cookies->new();
    $ua->cookie_jar( $cj );

    foreach (@symbols)
    {
		my $code = $_;

		my $code_type = "** Invalid **";
		if ($code =~ m/^[a-zA-Z]{2}[a-zA-Z0-9]{9}\d(.*)/ && !$1) { $code_type = "ISIN";  }
		elsif ($code =~ m/^[a-zA-Z0-9]{6}\d(.*)/ && !$1 )        { $code_type = "SEDOL"; }
		elsif ($code =~ m/^[a-zA-Z0-9]{4,6}(.*)/ && !$1)         { $code_type = "MEXID"; }

# current version can only use ISIN - report an error and exit if any other type

		if ($code_type ne "ISIN")
    	{
			$fundquote {$code,"success"} = 0;
			$fundquote {$code,"errormsg"} = "Error - invalid symbol";
			next;
    	}

		$fundquote {$code,"success"} = 1; # ever the optimist....
		$fundquote {$code,"errormsg"} = "Success";

# perform the look-up - if not found, return with error

# try listed funds first...

		my $webdoc  = $ua->get($FTFUNDS_LOOK_LD.$code);
    	if (!$webdoc->is_success)
		{
	        # serious error, report it and give up
			$fundquote {$code,"success"} = 0;
			$fundquote {$code,"errormsg"} =
		       		"Error - failed to retrieve fund data : HTTP status = ".$webdoc->status_line;
			next;
		}

DEBUG and print "\nTitle  = ",$webdoc->title,"\n";
DEBUG and print "\nStatus = ",$webdoc->status_line, "\n";
DEBUG > 1 and print "\nCookie Jar = : \n",Dumper($cj),"\n\n";

		$fundquote {$code, "source"} = $FTFUNDS_LOOK_LD.$code;

# if page contains "<h2>0 results</h2>" it's not found...
# ... try unlisted funds...

		if ($webdoc->content =~
        m[<h2>(0 results)</h2>] )
    	{
DEBUG and print "\nTrying unlisted funds for ",$code," : ",$1,"\n";
			$webdoc  = $ua->get($FTFUNDS_LOOK_UD.$code);
			if (!$webdoc->is_success)
        	{
	        	# serious error, report it and give up
				$fundquote {$code,"success"} = 0;
				$fundquote {$code,"errormsg"} =
		        		"Error - failed to retrieve fund data : HTTP status = ".$webdoc->status_line;
				next;
			}

DEBUG and print "\nTitle  = ",$webdoc->title,"\n";
DEBUG and print "\nStatus = ",$webdoc->status_line, "\n";
DEBUG > 1 and print "\nCookie Jar = : \n",Dumper($cj),"\n\n";

			$fundquote {$code, "source"} = $FTFUNDS_LOOK_UD.$code;
		}

		$fundquote {$code, "symbol"} = $code;

# Find name by simple regexp

        my $name;
		if ($webdoc->content =~
        m[<title>(.*) Summary - FT.com] )
        {
            $name = $1 ;
        }
		if (!defined($name)) {
			# not a serious error - don't report it ....
			# ... but set a useful message ....
			$fundquote {$code,"errormsg"} = "Warning - failed to find fund name";
			$name = "*** UNKNOWN ***";
			# ... and continue
		}
		$fundquote {$code, "name"} = $name;	# set name

# Find price
		my $price;
		if ($webdoc->content =~
		m[<div class="contains wsodModuleContent"><table><tbody><tr><td class="text first">([\.\,0-9]*)</td>]  )
        {
			$price   = $1;
        }
		if (!defined($price)) {
			# serious error, report it and give up
			$fundquote {$code,"success"} = 0;
			$fundquote {$code,"errormsg"} = "Error - failed to find a price";
			next;
		}
		if ($price =~ m[([0-9]*),([\.0-9]*)])
		{
				$price	  = $1 * 1000 + $2;
		}

# Find net and percent-age change
		my $net;
		my $pchange;
		if ($webdoc->content =~
		m[<span class="(pos|neg) color ">([\.0-9]*) / ([\.0-9]*)%</span>] )
        {
            $net = $2 ;     # allow for alternates in match string
            $pchange = $3;
        }
		if (!defined($net)) {
			# not a serious error - don't report it ....
#			$fundquote {$code,"success"} = 0;
			# ... but set a useful message ....
			$fundquote {$code,"errormsg"} = "Warning - failed to find a net change.";
			$net = "-0.00";					# ???? is this OK ????
			# ... and continue
		}
		if (!defined($pchange)) {
			# not a serious error - don't report it ....
#			$fundquote {$code,"success"} = 0;
			# ... but set a useful message ....
			$fundquote {$code,"errormsg"} = "Warning - failed to find a %-change";
			$pchange = "-0.00";					# ???? is this OK ????
			# ... and continue
		}
		if ($net =~ m[([0-9]*),([\.0-9]*)])
		{
			$net	  = $1 * 1000 + $2;
		}
		if ($pchange =~ m[([0-9]*),([\.0-9]*)])
		{
			$pchange	  = $1 * 1000 + $2;
		}

# Find the currency
		my $currency;
		if ($webdoc->content =~
                m[<th>(Price currency)</th><td>([A-Z]{3})</td>]  )
        {

			$currency    = $2;
        }

		if (!defined($currency)) {
			# serious error, report it and give up
			$fundquote {$code,"success"} = 0;
			$fundquote {$code,"errormsg"} = "Error - failed to find a currency";
			next;
		}

# deal with GBX pricing of UK unit trusts

		if ($currency eq "GBX")
		{
			$currency = "GBP" ;
			$price = $price / 100 ;
            $net   = $net   / 100 ;
		}

	# now set prices, net change and currency

		$fundquote {$code, "price"} = $price;
		$fundquote {$code, "last"} = $price;
		$fundquote {$code, "nav"} = $price;
        $fundquote {$code, "net"} = $net;
		$fundquote {$code, "currency"} = $currency;
		$fundquote {$code, "p_change"} = $pchange;	# set %-change

# Find time

# NB. version 2.0 - there is no time quoted on the current (31/3/2013) factsheet page for unit trusts
# ... this code left in in case it is available in later revisions of the page

		my $time;
		if ($webdoc->content =~ m[......... some string that will identify the time ............] )
        {
            if ($1 =~ m[(\d\d:\d\d)] )  # strip any trailing text (Timezone, etc.)
            {
                $time = $1;
            }
        }
		if (!defined($time)) {
			# not a serious error - don't report it ....
#			$fundquote {$code,"success"} = 0;
			# ... but set a useful message ....
			$fundquote {$code,"errormsg"} = "Warning - failed to find a time";
			$time = "17:00";	# set to 17:00 if no time supplied ???
                               	# gnucash insists on having a valid-format
			# ... and continue
		}

		$fundquote {$code, "time"} = $time; # set time

# Find date

		my $date;
		if ($webdoc->content =~
		m[([A-Za-z]{3}) ([0-9]{2}) ([0-9]{4})] )
        {
        	$date = "$2/$1/$3" ;
        }
		if (!defined($date)) {
			# not a serious error - don't report it ....
#			$fundquote {$code,"success"} = 0;
			# ... but set a useful message ....
			$fundquote {$code,"errormsg"} = "Warning - failed to find a date";
			# use today's date
			$quoter->store_date(\%fundquote, $code, {today => 1});
			# ... and continue
		}
		else
		{
			$quoter->store_date(\%fundquote, $code, {eurodate => $date});
		}

		$fundquote {$code, "method"} = "ftfunds";   # set method
		sleep 1;									# go to sleep for a while to give the web-site a breather

    }	# end of "foreach (@symbols)"

	return wantarray ? %fundquote : \%fundquote;
}

1;

=head1 NAME

Finance::Quote::FTfunds - Obtain UK Unit Trust quotes from FT.com (Financial Times).

=head1 SYNOPSIS

    $q = Finance::Quote->new;

    %info = Finance::Quote->fetch("ftfunds","<isin> ...");  # Only query FT.com using ISINs

=head1 DESCRIPTION

This module fetches information from the Financial Times Funds service,
http://funds.ft.com. There are over 47,000 UK Unit Trusts and OEICs quoted,
as well as many Offshore Funds and Exhange Traded Funds (ETFs). It converts
any funds quoted in GBX (pence) to GBP, dividing the price by 100 in the
process.

Funds are identified by their ISIN code, a 12 character alphanumeric code.
Although the web site also allows searching by fund name, this version of
Finance::Quote::FTfunds only implements ISIN lookup. To determine the ISIN for
funds of interest to you, visit the funds.ft.com site and use the flexible search
facilities to identify the funds of interest. The factsheet display for any given
fund displays the ISIN along with other useful information.

This module is loaded by default on a Finance::Quote object. It's
also possible to load it explicity by placing "ftfunds" in the argument
list to Finance::Quote->new().

Information obtained by this module may be covered by funds.ft.com
terms and conditions See http://funds.ft.com/ and http://ft.com for details.

=head2 Stocks And Indices

This module provides both the "ftfunds" and "ukfunds" fetch methods for
fetching UK and Offshore Unit Trusts and OEICs prices and other information
from funds.ft.com. Please use the "ukfunds" fetch method if you wish to have
failover with future sources for UK and Offshore Unit Trusts and OEICs - the
author has plans to develop Finance::Quote modules for the London Stock Exchange
and Morningstar unit trust services. Using the "ftfunds" method will guarantee
that your information only comes from the funds.ft.com website.

=head1 LABELS RETURNED

The following labels may be returned by Finance::Quote::ftfunds :

    name, currency, last, date, time, price, nav, source, method,
    iso_date, net, p_change, success, errormsg.


=head1 SEE ALSO

Financial Times websites, http://ft.com and http://funds.ft.com


=head1 AUTHOR

Martin Sadler, E<lt>martinsadler@users.sourceforge.netE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2010 by Martin Sadler

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.1 or,
at your option, any later version of Perl 5 you may have available.


=cut

__END__