2015-02-23 71 views
1

上午好!的Python的GData刪除資源

我跑我的覆盆子運動服務器。每當我的攝像頭捕捉動作時,它都會在我的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) 

我可能已經忘記了什麼,但我想不通。

非常感謝您的幫助!

回答

0

這麼多周後,與谷歌支持的球隊談話,似乎已刪除的文件只成爲孤兒這樣。我仍然有這些文件,他們仍然屬於我,但他們不在任何目錄(甚至根目錄)。

刪除它們的唯一方法是通過搜索是「自己的我」(在搜索選項)和手動刪除它們,爲的GData API不這樣做是正確的文件,此刻。