Skip to content

Instantly share code, notes, and snippets.

@ryunhe
Created January 16, 2014 03:00
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 ryunhe/8449130 to your computer and use it in GitHub Desktop.
Save ryunhe/8449130 to your computer and use it in GitHub Desktop.
import qiniu.conf
qiniu.conf.ACCESS_KEY = "<AKEY>"
qiniu.conf.SECRET_KEY = "<SKEY>"
import qiniu.rs
import qiniu.rsf
import datetime
def list_all(bucket_name, prefix=None, limit=100, days=30):
d = datetime.datetime.now() - datetime.timedelta(days)
delta = int(d.strftime("%s")) * 10000000
rs = qiniu.rsf.Client()
marker = None
err = None
while err is None:
ret, err = rs.list_prefix(bucket_name, prefix=prefix, limit=limit, marker=marker)
marker = ret.get('marker', None)
for item in ret['items']:
if item['fsize'] == 0 or item['putTime'] < delta :
print item
qiniu.rs.Client().delete(bucket_name, item['key'])
pass
if err is not qiniu.rsf.EOF:
print 'error'
pass
list_all('cactus', 'cactus/imgp/', 100, 30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment