我试图将雅虎价格输入 sqlite... 我有下面的代码,但无法将数据输入 ipull [] 然后输入 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()