【发布时间】:2020-07-21 00:15:19
【问题描述】:
我制作了一个在谷歌云虚拟机上运行的机器人。我一切正常,为了访问我的机器人正在写出的数据,我必须打开 Google Cloud SDK Shell 并输入:
gsutil cp gs://bucket_name/file.xlsx C:\\Users\\User\\Documents\\file.xlsx
我在 3rd 方服务器上制作机器人的麻烦的全部意义在于尽可能地自动化流程。所以我想知道是否有任何方法可以让我编写一个告诉 GC SDK Shell 运行上述命令的 python 脚本。甚至更好:当我打开某个 Excel 文件时运行上面的命令?也许后者实在太好了,令人难以置信。让我知道你的想法,谢谢!
Python 代码:
import google
from google.cloud import storage
def download_blob(bucket_name, source_blob_name, destination_file_name):
bucket_name = "gs://bot-example"
source_blob_name = "Koersen.xlsx"
destination_file_name = "C:\\Users\\User\\Documents\\Koersen.xlsx"
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)```
【问题讨论】: