File indexing completed on 2024-04-28 05:04:02
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.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 a file 0027 0028 # Configuration section 0029 # List of symbols to be downloaded 0030 @syms=(WMB,AAON,CSCO,EP,FLVCX,FSCGX,ISSC,MSFT,NOEQX,NOSIX,NTCHX,PG,RHT,SLR,FCNTX,FPURX,FJPNX,FSENX,OSMVX,ALU,TCLFX,FSLBX,FDFAX,FDIVX,ARTMX,EPD,FDGFX,OBFVX,TCLFX,OBBC,FDIKX,FDGFX); 0031 0032 # Filename of outputfile 0033 $file = "/var/datadl/quotes.csv"; 0034 0035 # No more configuration beyond this point 0036 0037 #use strict; 0038 use Getopt::Long; 0039 use Finance::YahooQuote; 0040 0041 my $verbose = 0; 0042 #GetOptions("verbose" => \$verbose); 0043 0044 #die "Usage: $0 [--verbose] symbol [symbol ...]\n" if $#ARGV == -1; 0045 0046 my @h = ("Symbol","Name","Last","Trade Date","Trade Time","Change","% Change", 0047 "Volume","Avg. Daily Volume","Bid","Ask","Prev. Close","Open", 0048 "Day's Range","52-Week Range","EPS","P/E Ratio","Div. Pay Date", 0049 "Div/Share","Div. Yield","Mkt. Cap","Exchange"); 0050 0051 $Finance::YahooQuote::TIMEOUT = 30; 0052 0053 my @q = getquote(@syms); 0054 open(FH, ">> $file") || die $!; 0055 foreach $a (@q) { 0056 print FH "!Type:Prices\n"; 0057 foreach (0..$#h) { 0058 if ($verbose) { 0059 print "$h[$_]: $$a[$_]\n"; 0060 } else { 0061 print FH "\"$$a[$_]\"," if $h[$_] =~ /(Symbol)/m; 0062 print FH "\"$$a[$_]\"\n" if $h[$_] =~ /(Trade Date)/m; 0063 # print FH "$$a[$_]\n" if $h[$_] =~ /(Symbol)/m; 0064 print FH "$$a[$_]," if $h[$_] =~ /(Last)/m; 0065 } 0066 } 0067 print FH "^\n"; 0068 } 0069 close(FH);