开发者

Get data into sqlite from yahoo finance

I trying to get yahoo prices into sqlite... I have the code below, but cant get the data into ipull [] then into sqlite...

from urllib import urlopen  
import win32com.client as win32  
import sqlite3

RANGE = range(3, 8)  
COLS = ('TICKER', 'PRICE', 'Vol')  
URL = 'http://quote.yahoo.com/d/quotes.csv?s=%s&f=sl1v' 
TICKS = ('GGP', 'JPM', 'AIG', 'AMZN')  
ipull =[]

def excel():
    app = 'Excel'
    xl = win32.gencache.EnsureDispatch('%s.Application' % app)
    ss = xl.Workbooks.Add()
    sh = ss.ActiveSheet
    xl.Visible = True

    for x in range(3):
        sh.Cells(5,开发者_StackOverflow中文版 x+1).Value = COLS[x]
    row = 6

    u = urlopen(URL % ','.join(TICKS))

    for data in u:
        tick, price, per  = data.split(',')
        sh.Cells(row, 1).Value = eval(tick)
        sh.Cells(row, 2).Value = ('%.2f' % float(price))
        sh.Cells(row, 3).Value = eval(per.rstrip())
        row += 1
    u.close()

con = sqlite3.connect('/py/data/db2') 
c = con.cursor()

c.execute('INSERT INTO prices VALUES (?,?,?)', ipull)

con.commit()  
c.close()

if __name__=='__main__':
    excel()


You declare ipull[], but never assign it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜