File indexing completed on 2024-07-21 04:36:26

0001 #!/usr/bin/perl -w
0002 
0003 #***************************************************************************
0004 # SPDX-FileCopyrightText: 2012 Joe W. Byers <financialseal@financialseal.com>
0005 # SPDX-License-Identifier: GPL-2.0-or-later
0006 #***************************************************************************/
0007 
0008 # Simple script to download security prices from finance.yahoo and create a 
0009 # qif format for KMyMoney.
0010 # Run by './fy-qif-history.pl' .
0011 # You are required to specify a directory and file location in line  57.
0012 # You should edit the list of security symbols in line 42.
0013 # This file can be scheduled as a cron job if needed
0014 
0015 # Output format -
0016 # !Type:Prices
0017 # "HJU8.BE",61.62,"23.12.09"
0018 # ^
0019 
0020 # This uses perl-Finance-YahooQuote
0021 # SPDX-FileCopyrightText: 2002 Dirk Eddelbuettel <edd@debian.org>, and GPL'ed
0022 # Based on the original example by Dj Padzensky
0023 #
0024 # $Id: yahooquote,v 1.2 2002/12/24 17:50:28 edd Exp $
0025 
0026 #Todo: create a file read to read in security symbols
0027 
0028 #use strict;
0029 use Getopt::Long;
0030 use Finance::QuoteHist::Yahoo;
0031 use HTTP::Date;
0032 use DateTime;
0033 use DateTime::Format::Flexible;
0034 
0035 #@syms=qw("WMB AAON");
0036 # CSCO EP FLVCX FSCGX ISSC MSFT NOEQX NOSIX NTCHX PG RHT SLR
0037 #       FCNTX FPURX FJPNX FSENX OSMVX ALU TCLFX FSLBX FDFAX FDIVX ARTMX EPD FDGFX OBFVX TCLFX 
0038 #       OBBC FDIKX FDGFX");
0039 $padlen = 2;
0040 
0041 
0042 #print "@syms";
0043 
0044 my $verbose = 0;
0045 my $q = new Finance::QuoteHist::Yahoo (
0046     symbols    => [qw("WMB AAON CSCO EP FLVCX FSCGX ISSC MSFT NOEQX NOSIX NTCHX PG RHT SLR
0047         FCNTX FPURX FJPNX FSENX OSMVX ALU TCLFX FSLBX FDFAX FDIVX ARTMX EPD FDGFX OBFVX TCLFX 
0048         OBBC FDIKX FDGFX")],
0049         start_date => '1/1/2010',
0050     end_date   => 'today'
0051     );
0052 
0053 $file = "/var/datadl/quoteshist.csv";
0054 open(FH, ">> $file") || die $!;
0055 
0056 
0057 #values
0058 foreach $row ($q->quotes()) {
0059   print FH "!Type:Prices\n";
0060     ($symbol, $date, $close) = @$row;
0061 #print "$symbol\n";
0062       print FH "Y$symbol" . ",";
0063       $yr=substr($date,0,4);
0064       $mm = substr($date,5,2);
0065       $mm = sprintf("%0${padlen}d", $mm);
0066       $dd = substr($date,8,2);
0067       #$dd=sprintf("%0${padlen}d", $d);
0068       #print "$date\n";
0069       print FH "  $mm/$dd/$yr" . "\n";
0070       print FH "I$close\n";
0071       print FH "^\n";
0072 
0073 #  print @$row["$symbol"]; print "=="; print @$row[ "$date"] ; 
0074 
0075 }
0076 close(FH);