Hi guys,

The Brits amongst us have horrendous problems downloading prices from
Yahoo, esp. if you want to download OEICS/Unit Trusts. It seems that
Yahoo is constantly fiddling with the layout on the server, meaning
that download scripts require ongoing maintenance.

To that end, I post my latest and greatest version of getquote-uk.py
below. There's only a minor tweak: we now download from
uk.old.finance.yahoo.com instead of uk.finance.yahoo.com. The presence
of the word "old" is a bit disturbing - I can only hope that this
doesn't bode ill for the future.

Enjoy!

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, string, sys

def download(sym):
    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])/100
    return result


sym = sys.argv[1]
sym = sym.replace('_', '.')
if sym == '£':
    print '£1.00'
else:
    try: print "£" +str(download(sym))
    except: pass

Reply via email to