Morning everyone!
I'm running a motion server on my Raspberry. It uploads videos on my GDrive everytime a motion is captured by my webcam.
I'm using GData to handle file transfers.
I also run a python script everyday at 5:00 AM to clean up the directory containing videos and removing every video that is older than 30 days. I'm able to connect, list resources, upload video, etc.
But here's my problem: When I try to delete resources, files are successfully removed from my Drive. Well, let's say they're not visible anymore. But when I take a look at my storage quota, it isn't modified. I've looked in the trash and in the original directory but they're not inside both of them.
Here's my script:
#!/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)
I may have forgotten something, but I can't figure out.
Thanks a lot for your help!
So after many weeks, talking with the Google Support's team, it appears that files deleted this way only become orphans. I still have this files, they still belong to me, but they aren't in any directory (not even the root).
The only way to delete them is by searching files that are "own by me" (in the search options) and delete them manually, as the GData API doesn't do it correctly, at the moment.