Te pongo mi rutina de actualización (en python). La clave está en la linea:
url = '''http://quote.yahoo.com/d/quotes.csv?s="%s"&f=snl1d1t1c1p2'''
en el %s se incorporan los valorez de mi cartera y el señor yahoo me devuelve muy amablemente un fichero csv con todo lo que le pido.
Que nadie critique mi código que sólo soy un aficionado ;-)
Saludos
Edito para decir que se ha perdido el formato... :-(
def posopreu(self, crida='sit'):
sql = ''' select yahoo from valor where yahoo is not null
union
select monyahoo from valor where monyahoo is not null '''
cr = db.bind.execute(sql)
vals = set()
for lin in cr:
vals.add(lin[0])
cr.close()
url = '''http://quote.yahoo.com/d/quotes.csv?s="%s"&f=snl1d1t1c1p2''' % (','.join(vals))
u = urlopen(url)
for row in csv.reader(u):
if row[3].upper() == 'N/A':
dia = '31.12.1900'
hora = '00:00'
else:
mm,dd,aa = row[3].split('/')
dia = '.'.join([dd,mm,aa])
if row[4] == 'N/A':
hora = '00:00'
else:
hh = row[4].replace('am','').replace('pm','')
hh, mm = hh.split(':')
if 'pm' in row[4]:
hh = int(hh)+12
hh = int(hh)+6
while hh > 23:
hh -= 24
hora = '%s:%s' % (hh, mm)
varpreu = row[5].replace('%','').replace('N/A','0')
varpc = row[6].replace('%','').replace('N/A','0')
sql = '''update valor set preu = '%s',
diaultim = '%s',
horaultim= '%s',
varpreu = %s,
varpc = %s
where yahoo = '%s' ''' % (row[2], dia, hora, varpreu, varpc, row[0])
db.bind.execute(sql)
sql = '''update valor set canvi = '%s' where monyahoo = '%s' ''' % (row[2], row[0])
db.bind.execute(sql)
db.commit()
sql = '''update valor set canvi = 1 where monyahoo is null '''
db.bind.execute(sql)
db.commit()
# El canvi del fons no l'agafa be. 25/9 -> 22.293726
sock = urlopen("http://es.finance.yahoo.com/q?s=BANKPYMESWIS.BC")
htm = sock.read()
sock.close()
cot = (htm[htm.find('yfs_l10_bankpymeswis.bc')+25:][:5].replace(',','.'))
sql = '''update valor set preu = %s where valor = 'SWISS' and preu = 0 ''' % (cot)
db.bind.execute(sql)
db.commit()
session.close()
if crida == 'sit':
raise cherrypy.InternalRedirect('/sit')
elif crida == 'risc':
raise cherrypy.InternalRedirect('/risc')