Код: Выделить всё
if __name__ == "__main__":
ic("name=main in strategies_helperz")
print(plotly.__version__, kaleido.__version__)
# create data
data_original = generate_dummy_data(symbol="BTCUSDT", num_records=100)
# transform to dataframe
df = klines_to_dataframe(data_original)
fig = plot_ohlc(df=df, exchange="mexc")
user="ZEoJt367"
src_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
folder_path = os.path.join(src_path, "screenshots", user)
if not os.path.exists(folder_path):
ic(f'{folder_path} not existing, should create one!')
os.makedirs(folder_path)
fileName = os.path.join(folder_path, current_time + str(".png"))
saveScreenshot(fig=fig, fileName=fileName, width=800, height=500)
Код: Выделить всё
def saveScreenshot(fig, fileName, width=800, height=500):
ic(f"def saveScreenshot to ${fileName}")
try:
pio.write_image(fig=fig, file=fileName, width=width, height=height, engine="kaleido")
ic(f"image saved to ${fileName} !")
return True
except Exception as e:
ic(f"Error saving image: {e}")
@app.route('/api/klines_for_plotly///', methods=['POST'])
def apiKlinesForPlotly(exchange, symbol, timeframe):
ic(f"def apiKlinesForPlotly - POST - for ${exchange}, symbol: ${symbol}, timeframe: ${timeframe}")
klines_with_names=[]
if exchange == "mexc":
klines_mexc=getKlinesDataMexc(symbol=symbol, interval=timeframe)
for data in klines_mexc:
kline = Mexc_KLine(data)
klines_with_names.append(kline)
elif exchange == "binance":
klines_binance=getKlinesDataBinance(symbol=symbol, interval=timeframe)
for data in klines_binance:
kline = Binance_KLine(data)
klines_with_names.append(kline)
# transforming klines_with_names to pandas df
df=klinesWithNamesToDf(klines_with_names=klines_with_names)
# creating a plotly fig based on df
fig = plot_ohlc(df=df, exchange=exchange)
user="ZEoJt367"
src_path = os.path.dirname(os.path.abspath(__file__))
current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
folder_path = os.path.join(src_path, "screenshots", user)
if not os.path.exists(folder_path):
ic(f'{folder_path} not existing, should create one!')
os.makedirs(folder_path)
fileName = os.path.join(folder_path, current_time + str(".png"))
fig = plot_ohlc(df=df, exchange=exchange)
saveScreenshot(fig=fig, fileName=fileName, width=800, height=500)
fig_json = fig.to_json()
return fig_json
. . в этом сценарии. . saveScreenshot никогда не заканчивается??? Я установил предыдущую версию kaleido, как предлагали многие с подобными проблемами, но все равно безуспешно. . . Может ли быть так, что для использования в маршруте колбы функция должна быть асинхронной??
Подробнее здесь: https://stackoverflow.com/questions/793 ... th-kaleido
Мобильная версия