gpt4 book ai didi

python - 有没有办法用 python 将 html 文件(绘图)写入 azure 存储 blob?

转载 作者:行者123 更新时间:2023-12-03 05:19:34 25 4
gpt4 key购买 nike

我一直在尝试找到一种将 html 文件上传到 python 中的 azure 存储 blob 的方法。我尝试创建一个临时文件夹,保存 html 文件并从那里上传它。我也尝试过直接使用我的输出绑定(bind)来设置它(这不起作用)。

我已成功上传 JPEG,但我需要专门的 HTML 文件才能工作,因为它是用户动态的(它是使用 graph/plotly 库创建的)。

    def main(mytimer: func.TimerRequest,outputblob: func.Out[bytes],inputblob: bytes,mypictureblob: func.Out[func.InputStream]): 



def return_graph(final_difference):
final_difference = final_difference
fig = go.Figure()
fig.add_trace(go.Scatter(y=final_difference['Expected Supply'],x = final_difference.index,hoverinfo='x+y',
mode = 'lines',
fill='tozeroy'))

fig.update_layout(

title="24 Month Supply and Demand - Daily Peak Hour",
xaxis_title="Date",
yaxis_title="MW Surplus",
legend_title="",
font=dict(
family="Courier New, monospace",
size=15,
color="green"
))

fig.update_layout(
title={
'text': "24 Month Supply and Demand - Daily Peak Hour",
'y':0.9,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'})


dir_path = tempfile.gettempdir()
asf = fig.write_html(file = dir_path + '/ss.html')
# This is just the naïve method to just hopefully cram it in the azure storage
#mypictureblob.set(asf)
image_stream = BytesIO()
asf.savefig(image_stream)
image_stream.seek(0)
with BytesIO() as input_blob:
mypictureblob.set(image_stream)

缺少代码,但到目前为止它可以工作。这 100% 是输入/输出问题,或者我试图错误地找到我创建的临时文件夹。

下面是我的 JSON 函数文件:

enter image description here

最佳答案

我想通了,以防有人遇到这个问题寻找解决方案。

    def return_graph(final_difference):
final_difference = final_difference
fig = go.Figure()
fig.add_trace(go.Scatter(y=final_difference['Expected Supply'],x = final_difference.index,hoverinfo='x+y',
mode = 'lines',
fill='tozeroy'))

fig.update_layout(

title="24 Month Supply and Demand - Daily Peak Hour",
xaxis_title="Date",
yaxis_title="MW Surplus",
legend_title="",
font=dict(
family="Courier New, monospace",
size=15,
color="green"
))

fig.update_layout(
title={
'text': "24 Month Supply and Demand - Daily Peak Hour",
'y':0.9,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'})
tempFilePath = tempfile.gettempdir()
fp = tempfile.NamedTemporaryFile()

fig_div = fig.to_html()
mypictureblob.set(fig_div)

区别在于Fig.to_html 与Fig.write_html。

关于python - 有没有办法用 python 将 html 文件(绘图)写入 azure 存储 blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73394438/

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