4

出于天气处理的目的,我希望在 Google Cloud Storage 中自动检索每日天气预报数据。

这些文件在公共 HTTP URL ( http://dcpc-nwp.meteo.fr/openwis-user-portal/srv/en/main.home ) 上可用,但它们非常大(在 30 到 300 兆字节之间)。文件大小是主要问题。

在查看了之前的stackoverflow主题之后,我尝试了两种不成功的方法:

1/ 通过 Google App Engine 中的 urlfetch 第一次尝试

    从 google.appengine.api 导入 urlfetch

    url = "http://dcpc-nwp.meteo.fr/service..."
    结果 = urlfetch.fetch(url)

    [...] # 保存在 Google Cloud Storage 存储桶中的代码

但我在 urlfetch 行收到以下错误消息:

DeadlineExceededError: 等待来自 URL 的 HTTP 响应时超过了最后期限

2/ 通过 Cloud Storage Transfert 服务进行第二次尝试

根据文档,可以通过 Cloud Storage Transfert 服务直接将 HTTP 数据检索到 Cloud Storage 中: https ://cloud.google.com/storage/transfer/reference/rest/v1/TransferSpec#httpdata

但它需要下载前文件的大小和md5。此选项不适用于我的情况,因为该网站不提供这些信息。

3/有什么想法吗?

您是否看到任何解决方案可以将 HTTP 上的大文件自动检索到我的 Cloud Storage 存储桶中?

4

3 回答 3

2

3/ 使用 Compute Engine 实例的解决方法

由于无法使用 App Engine 或直接使用 Cloud Storage 从外部 HTTP 检索大文件,因此我使用了始终运行的 Compute Engine 实例的解决方法。

此实例定期检查是否有新的天气文件可用,下载它们并将它们上传到 Cloud Storage 存储桶。

出于可扩展性、维护和成本原因,我宁愿只使用无服务器服务,但希望:

  • 它在新的 f1-micro Compute Engine 实例上运行良好(不需要额外的包,如果 24/7 运行,每月只需 4 美元)
  • 如果实例和存储桶在同一区域,则从 Compute Engine 到 Google Cloud Storage 的网络流量是免费的(0 美元/月)
于 2017-07-16T19:21:48.873 回答
1

可以使用 curl -I 命令轻松快速地检索文件的 md5 和大小,如此链接https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests中所述。
然后可以将 Storage Transfer Service 配置为使用该信息。

另一种选择是使用无服务器云功能。它在 Python 中可能看起来像下面的东西。

import requests

def download_url_file(url):
    try:
        print('[ INFO ] Downloading {}'.format(url))
        req = requests.get(url)
        if req.status_code==200:
            # Download and save to /tmp
            output_filepath = '/tmp/{}'.format(url.split('/')[-1])
            output_filename = '{}'.format(url.split('/')[-1])
            open(output_filepath, 'wb').write(req.content)
            print('[ INFO ] Successfully downloaded to output_filepath: {} & output_filename: {}'.format(output_filepath, output_filename))
            return output_filename
        else:
            print('[ ERROR ] Status Code: {}'.format(req.status_code))
    except Exception as e:
        print('[ ERROR ] {}'.format(e))
    return output_filename
于 2019-01-16T18:05:40.050 回答
0

目前谷歌的Transfer Service需要MD5和size;我们知道,在像您这样的情况下,这可能很难处理,但不幸的是,我们今天没有很好的解决方案。

除非您能够通过自己(临时)下载文件来获得大小和 MD5,否则我认为这是您能做的最好的事情。

于 2017-07-12T17:01:51.830 回答