gpt4 book ai didi

python - 从雅虎财经获取数据到 sqlite

转载 作者:太空宇宙 更新时间:2023-11-03 19:35:58 24 4
gpt4 key购买 nike

我试图将 yahoo 价格输入 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()

最佳答案

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

关于python - 从雅虎财经获取数据到 sqlite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3553421/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com