【问题标题】:Python : List blobs inside the Azure container according to datePython:根据日期列出 Azure 容器内的 blob
【发布时间】:2021-09-15 12:27:30
【问题描述】:

我想列出 azure 容器中唯一的上周数据。我使用的python代码首先列出了整个数据,然后根据给定的if条件过滤它。

list1 = [a.name for a in container_client.list_blobs(name_starts_with='folder1/') if a.last_modified.date() in last_week]

这个命令所花费的时间随着folder1大小的增加而增加,那么他们有什么方法可以更有效地获取这个列表吗?

【问题讨论】:

  • 你见过这个问题吗? stackoverflow.com/questions/44777851/…
  • 我需要pythonic解决方案,他们给出的解决方案是命令行。
  • 我指的是答案说这不能由 SDK(.NET 或 Python)或 Rest API 完成,但目前只能由 PowerShell 完成。答案还提供了在文件名前加上日期前缀的替代方法,以便您可以使用“name_starts_with”参数查询它们。

标签: python azure azure-python-sdk


【解决方案1】:

谢谢Anupam ChandMustafa Salam。发布您的建议作为帮助其他社区成员的答案。

这不能由 SDK(.NET 或 Python)或 Rest API 完成,但目前只能由 PowerShell 完成。 This answer 还提供了在文件名前加上日期前缀的替代方法,以便您可以使用“name_starts_with”参数查询它们。

您可以使用 PowerShell 根据日期列出 Azure 容器中的 blob:

$StorageAccountName = "AccountName" 
$StorageAccountKey = "What_ever_your_key_is_123asdf5524523A=="
$Context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$ContainerName = "Container"

$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context `
| Where-Object{$_.LastModified.DateTime -gt (Get-Date).Date}

获取日期


$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context `
| Where-Object{$_.LastModified.DateTime -gt ((Get-Date).Date).AddDays(-1)}

排序对象

$Blobs = Get-AzureStorageBlob -Container $ContainerName -Context $Context `
| Where-Object{$_.LastModified.DateTime -gt (Get-Date).Date.AddDays(-1)} `
| Sort-Object -Property Date

您可以参考Is it possible to List Azure Blobs Where Last Modified Date > Some DateIs there a way to list blobs in AzureBlobStorage based on timestamp?Get list of blobs in container added after some date

【讨论】:

    猜你喜欢
    • 2022-12-17
    • 2022-01-10
    • 2021-04-24
    • 2019-01-18
    • 2022-01-05
    • 2012-01-17
    • 2016-01-27
    • 2018-12-23
    • 2019-03-25
    相关资源
    最近更新 更多