Difference between revisions of "Install the Example Quote Source"

From PalOMoney
Jump to navigation Jump to search
(Created page with "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...")
 
Line 1: Line 1:
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 ''interpreted'' by a python interpreter.*
+
PalOMoney includes an example external quote source, [http://#QuoteCSV.py 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]]
  
Because the Yahoo Finance api used does not return column headers to identify the fields in the .csv file, the example also includes an accompanying example schema file, QuoteCSVSchema.csv.  
+
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, [http://#QuoteCSVSchema.csv 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 these files to your python folder, and add an external method as follows:
+
Copy QuoteCSV.py and QuoteCSVSchema.csv to your python folder, and install the new method:
  
....
 
  
  
  
* Windows does not include a python interpreter, but you can download and install one for free. Python comes in multiple versions, and the latest version has been greatly improved, but does not work with older python scripts. The safest bet is to install version 2.7.3, which you can get at [http://www.python.org Python.org]. Because you frequently use the command interpreter to execute python scripts, it is handy to install python just on your C drive root, say at C:\python27.
+
<h4>QuoteCSV.py</h4>
 +
<code>
 +
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()
 +
</code>
 +
 
 +
<h4>QuoteCSVSchema.csv</h4>
 +
<code>
 +
Ticker, Close, Date, Time
 +
</code>
 +
 
 +
 
 +
<h4>Installing Python</h4>
 +
 
 +
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 [http://www.python.org 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.

Revision as of 23:01, 24 January 2013

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.