Python GData 删除资源

Python GData Delete Resource

大家早上好!

我正在 运行在我的 Raspberry 上安装一个动态服务器。每当我的网络摄像头捕捉到动作时,它就会将视频上传到我的 GDrive。

我正在使用 GData 处理文件传输。

我还在每天 5:00 上午 运行 一个 python 脚本来清理包含视频的目录并删除所有超过 30 天的视频。 我可以连接、列出资源、上传视频等

但这是我的问题: 当我尝试删除资源时,文件已成功从我的云端硬盘中删除。好吧,假设它们不再可见。但是当我查看我的存储配额时,它并没有被修改。 我查看了垃圾箱和原始目录,但它们都不在其中。

这是我的脚本:

#!/usr/bin/env python
# coding=utf8
import sys
import os
import time, os.path
import atom.data, gdata.client, gdata.docs.client, gdata.docs.data
import datetime

username = 'my_google_account'
password = 'my_google_password'

def cleanDirectory(directoryName, daysOld):
    oldestDate = (datetime.datetime.now() - datetime.timedelta(days=int(daysOld)))
    docsclient = gdata.docs.client.DocsClient(source='RPi Python-GData 2.0.17')
    print 'Logging in...'
    try:
        docsclient.ClientLogin(username, password, docsclient.source)
    except (gdata.client.BadAuthentication, gdata.client.Error), e:
        print 'Unknown Error: ' + str(e)
        exit()
    except:
        print 'Login Error, perhaps incorrect username/password'
        exit()

    print 'success!'

    try:
        folderResource = docsclient.GetAllResources(uri='https://docs.google.com/feeds/default/private/full/-/folder?title=' + directoryName + '&title-exact=true')
    except:
        print 'ERROR: Unable to retrieve resources'
        exit()

    # Get the resources in the folder
    contents = docsclient.GetResources(uri= folderResource[0].content.src)

    # Print out the title and the absolute link
    print 'Deleting entries that are older than the given time...'
    nextPage = contents.GetNextLink().href
    while(nextPage):
        for entry in contents.entry:
            date = datetime.datetime.strptime(str(entry.published.text)[:-1]+"000Z","%Y-%m-%dT%H:%M:%S.%fZ")
            isOlder = date < oldestDate
            if(isOlder):
                print str(entry.title.text)+" : " + str(date)+ " : OLDER, Deleting..."
                docsclient.DeleteResource(entry,True)
                print "Deleted"
            else:
                print str(entry.title.text)+" : " + str(date)+ " : YOUNGER"

            contents =  docsclient.GetResources(uri=nextPage)
        if(contents.GetNextLink()):
            nextPage = contents.GetNextLink().href
        else:
            for entry in contents.entry:
                date = datetime.datetime.strptime(str(entry.published.text)[:-1]+"000Z","%Y-%m-%dT%H:%M:%S.%fZ")
                isOlder = date < oldestDate
                if(isOlder):
                    print str(entry.title.text)+" : " + str(date)+ " : OLDER, Deleting..."
                    docsclient.DeleteResource(entry,True)
                    print "Deleted"
                else:
                    print str(entry.title.text)+" : " + str(date)+ " : YOUNGER"
            break;

if len(sys.argv)>1:
    directoryName = sys.argv[1]
    if len(sys.argv)>2:
        duration = sys.argv[2]
        cleanDirectory(directoryName,duration)

我可能忘记了什么,但我想不通。

非常感谢您的帮助!

因此,数周后,与 Google 支持团队交谈,似乎以这种方式删除的文件只会成为孤儿。我还有这些文件,它们仍然属于我,但它们不在任何目录中(甚至不在根目录中)。

删除它们的唯一方法是搜索 "own by me" 的文件(在搜索选项中)并手动删除它们,因为 GData API 没有正确执行,在时刻.