简体   繁体   中英

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, 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()

您声明ipull[] ,但从不分配它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM