Skip to content

Instantly share code, notes, and snippets.

@dmitry-mukhin
Last active June 2, 2017 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry-mukhin/6be69dc779ca09b822d1 to your computer and use it in GitHub Desktop.
Save dmitry-mukhin/6be69dc779ca09b822d1 to your computer and use it in GitHub Desktop.
delete uploadcare files older than 14 days
#!/bin/python
# installation:
# pip install pytz pyuploadcare==1.3.1
import pytz
from datetime import timedelta, datetime
from pyuploadcare import conf
from pyuploadcare.api_resources import FileList
MAX_LIFETIME = 14 # days
conf.pub_key = 'demopublickey'
conf.secret = 'demoprivatekey'
dt_cutoff = datetime.now(pytz.utc) - timedelta(days=MAX_LIFETIME)
if __name__ == '__main__':
for f in FileList(stored=True, request_limit=500, until=dt_cutoff):
print 'deleting {0}...'.format(f.uuid)
f.delete()
@zerc
Copy link

zerc commented Mar 10, 2016

For API verion 0.5:

FileList(stored=True, request_limit=500, starting_point=dt_cutoff, ordering='-datetime_uploaded')

@zerc
Copy link

zerc commented Mar 10, 2016

In case of old version pyuploadcare i.e. not from the master branch you just need to set:

conf.api_version = '0.4'

@dmitry-mukhin
Copy link
Author

this needs to be updated for batch delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment