我在S3存储桶中有文件。数据文件以标准标签末尾的日期命名。
例如,文件键如下所示:
test_file_2016-12-01.tar.gz
我希望将文件从日期x
下载到日期y
。我可以这样做:
conn = boto.connect_s3(host="s3-eu-west-1.amazonaws.com")
bucket = conn.get_bucket(bucket_name)
k = Key(bucket)
key_prefix = "test_file"
date_o = date(2016,11,30)
date_1 = date(2016,12,01)
day_delta = date_1 - date_o
for i in range(day_delta.days +1):
file_key = key_prefix + str(date_o + td(days=i)) + "tar.gz"
# Get the file
k.key = file_key
# Location for download destination
temp_location = "./tmp/" + file_key
k.get_contents_to_filename(temp_location)
但是,我现在正在收集更精细的分辨率数据,并希望以小时分辨率添加数据。
因此文件看起来像这样:
test_file_2016-12-01-10.tar.gz
我可以使用timedelta
的{{1}}功能很好地处理时间delta,但这也不支持datetime
。
如何调整此选项以指定在以下内容之间捕获文件:
hour