【发布时间】:2022-02-11 08:40:36
【问题描述】:
#所以基本上,以下代码从名为 finnhub 的导入中提取牲畜数据,基本上,它使用 API 提取连接到 JSON 文件的实时值。 [API对代码没有问题,第一部分几乎是我构建的以下或下一个代码的示例]问题出在第二部分,如果我可以打印出一个值而不是它去到终端它被存储在一个变量中]
import finnhub
import os
import sys
import time
finnhub_client = finnhub.Client(api_key="c82bn52ad3icth8l2dtg")
ticker = input("Type in your stock ticker here: ")
print("|c| means Current Price|,\n |d| means diffrence/change of price|,\n |dp| means Percent Change|,\n |h| highest price of the day(All time high)|,\n |l| means lowest price of the day|,\n |o| means open price of the day|, \n |pc| means Previous Close price|.")
price = finnhub_client.quote(ticker)
print(price["h"])
#h是你选择的以下股票在当天达到的最高价格, #所以我试图寻找一种方法将打印的输出从 print(price["h"]) 存储到一个变量而不打印到终端,然后在给定的秒数之后,一个新的代码打印相同的(price["h"]) 到一个新变量,那么比较起来会有一个旧变量和新变量都包含不同的值,所以如果旧变量>比新变量,它应该打印新变量价值。
#所以像这样,但它没有工作。
from hashlib import new
import finnhub
import os
import sys
import time
finnhub_client = finnhub.Client(api_key="c82bn52ad3icth8l2dtg")
ticker = input("Type in your stock ticker here: ")
Tkekr = ticker
def Stockalert(Tkekr):
print("|c| means Current Price|,\n |d| means diffrence/change of price|,\n |dp| means Percent Change|,\n |h| highest price of the day(All time high)|,\n |l| means lowest price of the day|,\n |o| means open price of the day|, \n |pc| means Previous Close price|.")
price = finnhub_client.quote(ticker)
#I'm trying to store the output of the first given high peak, then use it to compare it with another value printed after 30sec of another high peak,
#and if it is higher it will, autmoatically send a notification saying it has crossed it's highest peak
# print(price["h"])
old_stdout = print(price["h"])
time.sleep(60)
new_stdout = print(price["h"])
if old_stdout < new_stdout:
print(sys.stdout)
print(Stockalert(Tkekr))
#最初的目的是让代码打印出 h 并将值存储在变量中,然后在 60 秒或给定时间后,它在新变量中打印出另一个值,然后 if 命令/循环进入并比较旧变量和新变量,因此如果新变量 > 旧变量,它会将新变量及其存储的值返回给我。因此,如果变量中的新值高于旧值,它将打印一条消息,说明当天的最高峰现在是“此处插入了新值”。 到目前为止,这是我写的和得到的。
【问题讨论】:
标签: python pandas time repeat sys