Install the Example Quote Source

From PalOMoney
Revision as of 23:05, 24 January 2013 by Admin (talk | contribs)
Jump to navigation Jump to search

PalOMoney includes an example external quote source, QuoteCSV.py that gets quotes from Yahoo Finance and imports them into MS Money. QuoteCSV.py is a very simple python script. Python is a high level computer script-like language that is executed by a python interpreter. You might have python installed already to take advantage of the python solutions for updating MS Money quotes and bank statements, etc. See Installing Python

The Yahoo Finance api in the example does not return column headers to identify the fields in the .csv file, the example also includes an accompanying example schema file, QuoteCSVSchema.csv. Of course, it is trivial to modify the script to include the header line, but then we wouldn't have an example of a schema file to give you. Testers in particular should test using the separate schema file.

Copy QuoteCSV.py and QuoteCSVSchema.csv to your python folder, and install the new method:



QuoteCSV.py

import os, urllib2, sys
argv = sys.argv
if __name__=="__main__":
   if len(argv) < 3:
       print "Usage:",argv[0], "YahooURLSpec OutputFileName"
       if len(argv) > 0:
           print "1:", argv[1]
       if len(argv) > 1:
           print "2:", argv[2]
       sys.exit()
   #url = "http://finance.yahoo.com/d/quotes.csv?s=%s&f=nl1d1t1" % argv[1]
   url = argv[1]
   csv = urllib2.urlopen(url).read()
   f = file(argv[2],"w")
   f.write(csv)
   f.close()

QuoteCSVSchema.csv

Ticker, Close, Date, Time


Installing Python

Windows does not include a python interpreter, but you can download and install one for free. Python comes in a multitude of versions, and the latest version is of course improved, but it does not work with older python scripts. The safest bet is to install version 2.7.3, which you can get at Python.org. Because the command interpreter is frequently used to execute python scripts, it is handy to install python just on your C drive root, say at C:\python27. You will also have to download and install python libraries to extend the python's functionality.