Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

python script to download quotes for Quicken

221 views
Skip to first unread message

Section8

unread,
Feb 10, 2005, 2:46:04 AM2/10/05
to
I am a happy Q2001 user dealing also dealing with Intuit's sunset policy.
The one online quicken feature I can't live without is downloading
stock/mutual fund quotes.

In order to extend the life of Q2001, I have written a small python script
to download selected quotes from finance.yahoo.com, format them a little
for quicken's benefit, and merge them into a cumulative quote file for
later import into quicken.

I schedule this script to run once each day in the evening and then can
import the quote file at my leisure into quicken. After importing the
quote file, I delete it so it will start over the next day.

It requires python 2.3 or better, freely available for windows, linux, the
Mac, and others from http://www.python.org.

If you want to try this script, you will need to change the 'symbols'
variable in line 9 to your ticker symbols. This variable should be
formatted as shown, with each symbol in quotes, comma separated, enclosed
in []. The 'quotefile' variable in line 14 is the cumulative import file
it builds.

Feel free to use this - I've only used it with Q2001, so I can't vouch for
other quicken versions, but as long as the quote import format didn't
change, it should work.

Paste the text below into a text editor (the #!/usr/bin... line should be
the first line) and save it as "whatever.py" or you can get it here:

http://bookex.home.comcast.net/quotes.py

John

#!/usr/bin/env python

## Retrieve stock quotes from finance.yahoo.com and format them for
## import into Quicken

import sys, os, urllib, time

## Funds/stocks we will download:
symbols = [ 'MSFT', 'IBM', 'YHOO', 'INTU',
'GOOG' ]

urlprefix = 'http://finance.yahoo.com/d/quotes.csv?s='
urlsuffix = '&f=sl1d1t1c1ohgv&e=.csv'
quotefile = 'c:/quotes.csv'

def addquotes( s ):
""" add quotes (") to the input string """
if s.startswith('"'): return s
else: return '"' + s + '"'

# import pdb; pdb.set_trace()

quotes = []
if os.path.exists( quotefile ):
qfile = file( quotefile, 'r' )
quotes = qfile.readlines()
qfile.close

urls = ''
for symbol in symbols:
urls += ( symbol + '+' )

# download the quotes from yahoo:
url = urlprefix + urls[:-1] + urlsuffix
infile = urllib.urlopen( url )

# for each line downloaded from yahoo, scan the cumulative 'quotefile'
# for the same ticker symbol and quote date. If we find one, replace the
# old quote with the newest one from yahoo:
for line in infile:
fields = line.split( ',' )
# build a line of: "symbol","price","date"
fields = [ addquotes(x) for x in fields[0:3] ]
line = ",".join( fields ) + "\n"
found = False
for qx, quot in enumerate( quotes ):
qfields = quot.rstrip('\n').split( ',' )
if qfields[0] == fields[0] and qfields[2] == fields[2]:
# replace a duplicate with an updated line:
quotes[qx] = line
found = True
break

# if we didn't find this line in the quotes.csv file, append
# it to the end:
if not found:
quotes.append( line )

infile.close()

qfile = file( quotefile, 'w+' )
qfile.writelines( quotes )
qfile.close()

print 'done'


Joe

unread,
Feb 11, 2005, 12:57:10 PM2/11/05
to
Good job! I have 0 programming experience. I better start experimenting with
this now so hopefully by April when intuit cuts us lose I'll have it
working...

ps,

don't leave, I'll be asking for your help....

prediction- I think you are going to become very popular between now and
April

Section8

unread,
Feb 11, 2005, 9:01:10 PM2/11/05
to
Joe wrote:

> Good job! I have 0 programming experience. I better start experimenting
> with this now so hopefully by April when intuit cuts us lose I'll have it
> working...
>

Joe,
Thanks for the response.

Being a lurker here, I was beginning to wonder if anyone was going to try
it.

As a follow-up, I advise you to download the script from the url
( http://bookex.home.comcast.net/quotes.py ) and don't try to paste the
text from the OP into an editor.

Somewhere in the process of copy/pasting from my pc to usenet, some of the
white space characters in the script were changed - it looks like tabs
changed to blanks for example. Python doesn't like this, and when I tried
to cut/paste from the post and run it, python complained.

The copy at the url has all the white space preserved and should run
correctly.

Please reply if you have any problems

John

Joe

unread,
Feb 12, 2005, 12:42:38 AM2/12/05
to
I just setup a test system and installed Q2001, patched it to R3 and copied
& edited my quicken.ini for the test system, Q2001 is up and running in the
test system. I installed Python-2.3.5 and so far I've been able to create a
quotes.csv with today's quotes. I guess my next step is to edit the stock
symbols with my own and attempt to import that into Q2001? I'm fairly
certain I will need more help...Thanks again!


"Section8" <jdmo...@nospam.comcast.net> wrote in message
news:8_mdnRretY3...@comcast.com...

Joe

unread,
Feb 12, 2005, 8:01:23 AM2/12/05
to
I assume I copied the info correctly because the quote.csv is updating with
my quotes. How do you actually get the script to update Q2001? how & where
do you save the new script? Do you have to rename the script with a PY
extension and open it from Q2001?

TIA,

Joe

"Section8" <jdmo...@nospam.comcast.net> wrote in message
news:8_mdnRretY3...@comcast.com...

Joe

unread,
Feb 12, 2005, 11:09:35 AM2/12/05
to
First off, let me say THANK YOU for sharing this info. I hate when any
company does something like this, I've seen the newer versions and I'm sure
many people are enjoying the new versions but they just aren't for me.

Anyway, I have it updating Quicken by way of File\Import\Import Prices, I
think my problem was I had the most update to date prices to start with,, I
did a restore from a slightly older backup and that let me update from the
"quotes.csv", now I just have to make sure I'm accessing & saving the Pyton
script properly. I guess it's just a matter of some fine tuning

Thank you again!

"Section8" <jdmo...@nospam.comcast.net> wrote in message
news:8_mdnRretY3...@comcast.com...

Section8

unread,
Feb 12, 2005, 9:36:10 PM2/12/05
to
Joe wrote:

> I assume I copied the info correctly because the quote.csv is updating
> with my quotes. How do you actually get the script to update Q2001? how &
> where do you save the new script? Do you have to rename the script with a
> PY extension and open it from Q2001?
>
>

Joe,

Sorry for the confusion.

On most systems (windows at least), the script should be named with a .py
extension so windows will automatically run it in the python interpreter -
if you double click it or put a shortcut to it on your desktop.

Quicken doesn't interact directly with the script - you import the file the
script builds into quicken.

To import the quotes into quicken, open the portfolio view in quicken (Main
menu/Investing/Portfolio view) and then go to File menu/Import/Import
prices and give it the .csv file the script creates.

This script will be most useful to you if you want to keep a daily history
of security prices in your quicken portfolio. Each day you run it, it will
add that day's prices into the quotes.csv file. If you can schedule it to
run every day, (in the windows task scheduler, or cron in linux), you won't
have to do anything to have your stock prices downloaded daily. You can
just import the csv file into quicken whenever you get around to it.


Joe

unread,
Feb 13, 2005, 12:48:48 AM2/13/05
to
we are good to go! thanks again for making this available and taking the
time to explain it. your help is greatly appreciated.

"Section8" <jdmo...@nospam.comcast.net> wrote in message

news:0_idnf08raG...@comcast.com...

0 new messages