Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
谷歌云存储(Python):如何检查上次修改文件的时间?_Python_Google App Engine_Google Cloud Storage - Fatal编程技术网

谷歌云存储(Python):如何检查上次修改文件的时间?

谷歌云存储(Python):如何检查上次修改文件的时间?,python,google-app-engine,google-cloud-storage,Python,Google App Engine,Google Cloud Storage,我们有一项任务,检查云存储上的文件是否已被修改。如果是这样,则从文件中读取数据并进一步处理 我想知道是否有API可用于检查云存储上的文件上次修改的时间。云存储有一个API,可用于获取对象的创建时间 请参见您可以通过以下方式执行此操作: 还有一个到云存储的应用程序,但我认为它不会公开您想要的元数据。应用程序引擎会向您公开这些信息。该库还支持dev-appserver。开始有一个重要的意义 您现在可以使用 在您的情况下,您必须查看blob.updated属性我正在使用上面@orby提到的解决方案,使

我们有一项任务,检查云存储上的文件是否已被修改。如果是这样,则从文件中读取数据并进一步处理


我想知道是否有API可用于检查云存储上的文件上次修改的时间。

云存储有一个API,可用于获取对象的创建时间

请参见

您可以通过以下方式执行此操作:


还有一个到云存储的应用程序,但我认为它不会公开您想要的元数据。

应用程序引擎会向您公开这些信息。该库还支持dev-appserver。开始有一个重要的意义

您现在可以使用


在您的情况下,您必须查看
blob.updated
属性我正在使用上面@orby提到的解决方案,使用
blob.updated
获取最新文件。但是bucket中有450多个文件,这个脚本大约需要6-7分钟来浏览所有文件并提供最新的文件。我想
blob.updated
部分需要一些时间来处理。有没有更快的办法

    files = bucket.list_blobs()    
    fileList = [file.name for file in files if '.dat' in file.name]
     
    latestFile = fileList[0]
    latestTimeStamp = bucket.get_blob(fileList[0]).updated
            
    for i in range(len(fileList)):
        
        timeStamp = bucket.get_blob(fileList[i]).updated
        
        if timeStamp > latestTimeStamp:
            latestFile = fileList[i]
            latestTimeStamp = timeStamp
    
    print(latestFile)

没有用于此的Python API吗?我们的代码是用Python编写的。Google API Client Library for Python支持beta云存储API:尽管您需要在API仪表板上首先请求访问来启用此功能。是的,他们似乎不支持云存储API,而支持新的客户端库。
from google.cloud import storage


def blob_metadata(bucket_name, blob_name):
    """Prints out a blob's metadata."""
    # bucket_name = 'your-bucket-name'
    # blob_name = 'your-object-name'

    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)
    blob = bucket.get_blob(blob_name)

    print("Blob: {}".format(blob.name))
    print("Bucket: {}".format(blob.bucket.name))
    print("Storage class: {}".format(blob.storage_class))
    print("ID: {}".format(blob.id))
    print("Size: {} bytes".format(blob.size))
    print("Updated: {}".format(blob.updated))
    print("Generation: {}".format(blob.generation))
    print("Metageneration: {}".format(blob.metageneration))
    print("Etag: {}".format(blob.etag))
    print("Owner: {}".format(blob.owner))
    print("Component count: {}".format(blob.component_count))
    print("Crc32c: {}".format(blob.crc32c))
    print("md5_hash: {}".format(blob.md5_hash))
    print("Cache-control: {}".format(blob.cache_control))
    print("Content-type: {}".format(blob.content_type))
    print("Content-disposition: {}".format(blob.content_disposition))
    print("Content-encoding: {}".format(blob.content_encoding))
    print("Content-language: {}".format(blob.content_language))
    print("Metadata: {}".format(blob.metadata))
    print("Temporary hold: ", "enabled" if blob.temporary_hold else "disabled")
    print(
        "Event based hold: ",
        "enabled" if blob.event_based_hold else "disabled",
    )
    if blob.retention_expiration_time:
        print(
            "retentionExpirationTime: {}".format(
                blob.retention_expiration_time
            )
        )
    files = bucket.list_blobs()    
    fileList = [file.name for file in files if '.dat' in file.name]
     
    latestFile = fileList[0]
    latestTimeStamp = bucket.get_blob(fileList[0]).updated
            
    for i in range(len(fileList)):
        
        timeStamp = bucket.get_blob(fileList[i]).updated
        
        if timeStamp > latestTimeStamp:
            latestFile = fileList[i]
            latestTimeStamp = timeStamp
    
    print(latestFile)