Greetings accountancy fans, I've been doing some minor tweaking with the quote downloading software written in python. I have renamed getquote-uk.py to getquoteuk.py so that it can be loaded as a module. I have also done a little bit of refactoring so that it can be called both from the command line, and be used as a module. The function download() now contains an optional parameter SCALE, which can be used to scale the answer before output. This is useful where, for example, you obtain the value for an index, where you want the scale to be 1, as opposed to a normal stock/share, where you want the scale to be 100 (which is the default).
I attach the updated version of the python script, together with a bash script called getquote - which is a simple wrapper for the python module. Minor plug for my own software: TACC - a Tcl package to manipulate the output from ledger-cli. It has a REPL, and you can do neat things like find the IRR for a portfolio: http://github.com/blippy/tacc/tree/master
getquote
Description: Binary data
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 30-Apr-2009 Introduced main(), enhanced download()
import urllib, string, sys
def download(sym, scale = 100):
url = "http://uk.old.finance.yahoo.com/d/quotes.csv?s="
url += sym + "&f=sl1d1t1c1ohgv&e=.csv"
f = urllib.urlopen(url, proxies={})
info = f.read()
f.close()
fields = string.split(info, ',')
result = float(fields[1])/scale
return result
def main():
sym = sys.argv[1]
sym = sym.replace('_', '.')
currency = '' # replace by local currency - but probably keep it blank
if sym == '':
print currency + '1.00'
else:
try: print currency +str(download(sym))
except: pass
if __name__ == "__main__": main()
