gpt4 book ai didi

python - 如何通过我在 Google App Engine 中的应用程序将文件写入 Google Cloud Storage?

转载 作者:搜寻专家 更新时间:2023-10-30 22:24:58 24 4
gpt4 key购买 nike

我正在寻找一种非常简单的方法来创建文件并通过我在 Google App Engine 中运行的应用程序向其中写入文本数据(我猜是在我的 Google Cloud Platform 存储桶中)。为此,我需要在我的代码中使用哪些库/函数?我用谷歌搜索了这个废话,但我没有找到任何简单的方法来做到这一点。

我是编码新手,所以如果您提供代码示例,我将不胜感激!提前致谢:)

详细信息:在该应用程序中,每当用户想要在另一个网站上搜索内容时,我都会在另一个网站上抓取 250 个网页。这当然会在服务器上产生极重的负载,更不用说用户必须等待长达 45 秒才能看到结果。为了解决这个问题,我想我应该设置一个 cron 作业,每隔 5 分钟左右抓取一次这些网页,并将它们的内容存储在某个文件中(最好是 250 个不同的文件),稍后应用程序会在搜索过程中访问这些文件查询。

最佳答案

使用这个库:https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/functions

像这样

import cloudstorage
with cloudstorage.open('/---bucket-name---/path/within/bucket/file.html', 'w') as f:
f.write(content)

关于python - 如何通过我在 Google App Engine 中的应用程序将文件写入 Google Cloud Storage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54336609/

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