终极虚拟个人助理功能拓展与音频模块安装指南
1. 股票市场跟踪功能
在虚拟个人助理(VPA)中添加股票市场跟踪功能,可以让你实时获取股票价格和市场指数。
1.1 股票价格查询功能
以下是实现股票价格查询功能的代码:
# Prevent crashing in case there is no result
try:
# Extract the source code from the website
url = 'https://query1.finance.yahoo.com/v1/finance/search?q='+myfirm
response = requests.get(url)
# Read the JSON data
response_json = response.json()
# Obtain the value corresponding to "quotes"
quotes = response_json['quotes']
# Get the ticker symbol
ticker = quotes[0]['symbol']
# Obtain real-time stock price from Yahoo
price = round(float(si.get_live_price(ticker)),2)
# Speak the stock price
print_say(f"the stock price for {myfirm} is {price} dolla
超级会员免费看
订阅专栏 解锁全文
2556

被折叠的 条评论
为什么被折叠?



