Beispiel #1
0
def list_all(bucketName, rs=None, prefix=None, limit=None):
    '''
	sample code from official api page
	'''

    qiniu.conf.ACCESS_KEY = QiNiuACCESS_KEY
    qiniu.conf.SECRET_KEY = QiNiuSECRET_KEY

    if rs is None:
        rs = qiniu.rsf.Client()
    marker = None
    err = None
    while err is None:
        ret, err = rs.list_prefix(bucketName,
                                  prefix=prefix,
                                  limit=limit,
                                  marker=marker)
        marker = ret.get('marker', None)
        # print ret
        return ret['items']
        for item in ret['items']:
            # #do something
            pass
    if err is not qiniu.rsf.EOF:
        #error handling
        pass
Beispiel #2
0
    def _get_files(self):
        rs = qiniu.rsf.Client()
        files = []
        marker = None
        error = None
        while error is None:
            ret, error = rs.list_prefix(self.bucket_name, prefix = self.prefix, marker = marker)
            marker = ret.get('marker', None)
            files += [item['key'] for item in ret['items'] if item['key'] not in files]

        return files
Beispiel #3
0
	def run(self):
		marker = None
		err = None
		rs = rsf.Client()
		while err is None:
			ret, err = rs.list_prefix(bucket_name, prefix=dbprefix, limit=10, marker=marker)
			marker = ret.get('marker', None)
			for item in ret['items']:
				print item
				self.deleteTile(item["key"])

		if err is not rsf.EOF:
			print err
Beispiel #4
0
def list_all(bucket, rs=None, prefix=None, limit=None):
	if rs is None:
		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']:
			#do something
			pass
	if err is not qiniu.rsf.EOF:
		# 错误处理
		pass
Beispiel #5
0
def list_all_photo(bucket,size=100, rs=None, prefix=None, limit=None):
    photos = []
    if rs is None:
        rs = qiniu.rsf.Client()
    marker = None
    err = None
    while err is None:
        ret, err = rs.list_prefix(bucket, prefix=prefix, limit=limit, marker=marker)
        marker = ret.get('marker', None)
        for item in ret['items']:
            photos.append(("http://" + conf.qiniu_domain + "/" + item['key'], get_image_preview(item['key'], size)))
            pass
    if err is not qiniu.rsf.EOF:
        # 错误处理
        pass
    return photos
def clear_all(bucket, rs=None, prefix=None, limit=None):
    if rs is None:
        rs = qiniu.rsf.Client()
    marker = None
    err = None
    files = []
    while err is None:
        ret, err = rs.list_prefix(bucket, prefix=prefix, limit=limit, marker=marker)
        marker = ret.get('marker', None)
        for item in ret['items']:
            files += ret['items']
    if err is not qiniu.rsf.EOF:
        sys.stderr.write('error: %s ' % err)
    else:
        keys = [qiniu.rs.EntryPath(bucket, x['key']) for x in files]
        rets, err = qiniu.rs.Client().batch_delete(keys)
    return len(files)
Beispiel #7
0
def list_all(bucket_name='cntrains', rs=None, prefix=None, limit=None):
    logger.info('list_all started')
    if rs is None:
        rs = qiniu.rsf.Client()
    marker = None
    err = None
    files = []
    while err is None:
        ret, err = rs.list_prefix(bucket_name,
                                  prefix=prefix,
                                  limit=limit,
                                  marker=marker)
        marker = ret.get('marker', None)
        files += ret['items']
    if err is not qiniu.rsf.EOF:
        pass
    logger.info('got files from qiniu')
    logger.info('connect to redis')

    def _get_redis():
        password = os.environ.get('REDIS_PASSWORD', None)
        if password:
            r = redis.StrictRedis(host=os.environ['REDIS_PORT_6379_TCP_ADDR'],
                                  port=os.environ['REDIS_PORT_6379_TCP_PORT'],
                                  db=0,
                                  password=password)
        else:
            r = redis.StrictRedis(host=os.environ['REDIS_PORT_6379_TCP_ADDR'],
                                  port=os.environ['REDIS_PORT_6379_TCP_PORT'],
                                  db=0)
        return r

    try:
        r = _get_redis()
        r.set('files', jsonpickle.encode(files))
        r.set('files_updated_at', str(datetime.now()))
        logger.info('update to redis')
    except Exception, e:
        logger.error(e)
Beispiel #8
0
def list_all(bucketName, rs=None, prefix=None, limit=None):
	'''
	sample code from official api page
	'''

	qiniu.conf.ACCESS_KEY = QiNiuACCESS_KEY
	qiniu.conf.SECRET_KEY = QiNiuSECRET_KEY
	
	if rs is None:
		rs = qiniu.rsf.Client()
	marker = None
	err = None
	while err is None:
		ret, err = rs.list_prefix(bucketName, prefix=prefix, limit=limit, marker=marker)
		marker = ret.get('marker', None)
		# print ret
		return ret['items']
		for item in ret['items']:
			# #do something
			pass
	if err is not qiniu.rsf.EOF:
		#error handling
		pass
    def list_directory(self, path=None):
        try:
            path = self._init_path(path)
            rs = qiniu.rsf.Client()
            marker = None
            err = None
            counter = 0

            while err is None:
                ret, err = rs.list_prefix(self._bucket, prefix=path, marker=marker)
                marker = ret.get('marker', None)
                for item in ret['items']:
                    counter += 1
                    yield item['key']

            if err is not qiniu.rsf.EOF:
                print err
                raise IOError("List path %s err: %s" % (path, err))

            if counter == 0:
                print 'empty'
                Exception("empty")
        except Exception as e:
            raise exceptions.FileNotFoundError('%s is not there err: %s' % (path, e))
Beispiel #10
0
def list_all(bucket, rs=None, prefix=None, limit=None):
    count = 0
    if rs is None:
        rs = qiniu.rsf.Client()
    marker = None
    err = None
    s = requests.Session()
    #while err is None and count<10:
    while err is None :
        ret, err = rs.list_prefix(bucket, prefix=prefix, limit=limit, marker=marker)
        marker = ret.get('marker', None)
        for item in ret['items']:
            post_id = item['key'].split('_',1)[0]
            print 'post_id:',post_id
            if len(post_id) < 20:
                continue 
            post_info = mdb.baidu.post.find_one({'_id':ObjectId(post_id)})
            if  not post_info:
                print '帖子已经被删了'
                qiniu.rs.Client().delete(bucket,item['key'])
                continue
            try:
                print 'img info:',item
                if item.get('fsize',0) < 10240:
                    print '删图太小的图片'
                    qiniu.rs.Client().delete(bucket,item['key'])
                else:
                    print '发现需要保存的图片'
                    img_url = "http://tiebaimg.qiniudn.com/"+item['key']
                    img_data = s.get(img_url).content 
                    f = open("%s/%s"%("share",item['key']), "wb")
                    f.write(img_data)
                    f.close()
            except Exception,e:
                continue
        count+=limit
Beispiel #11
0
#coding:utf-8
import datetime
import json
import qiniu.rsf
import qiniu.conf
import qiniu.rs


qiniu.conf.ACCESS_KEY = "W4nYpf8HOCEyCzjLHpO0QVYGOykRucI1MIniLpgL"
qiniu.conf.SECRET_KEY = "3NRgrf8v_XHGGoWROaXYZoFYPvSeN3HnI_19eVfk"
qiniuSpace="cdmmstatic"

todel_file=[]

rs = qiniu.rsf.Client()
marker = None
err = None
while err is None:
    ret, err = rs.list_prefix(qiniuSpace, prefix="", limit=1000, marker=marker)
    marker = ret.get('marker', None)
    for item in ret['items']:
        todel_file.append("http://cdmmstatic.qiniudn.com/"+item['key'])

print json.dumps(todel_file,ensure_ascii=False,indent=2)
Beispiel #12
0
import qiniu.conf
import qiniu.rs


qiniu.conf.ACCESS_KEY = "x5yGWWp6fBGMwlJyEU0GVzilkNIa7Mc87ibrKpdU"
qiniu.conf.SECRET_KEY = "r_8i1p4LCaiI0isFxuF2paAKhoQotGeqngCD4B1O"
qiniuSpace="kidswant"

beforetime=datetime.datetime(year=2014,month=1,day=10)
todel_file=[]

rs = qiniu.rsf.Client()
marker = None
err = None
while err is None:
    ret, err = rs.list_prefix(qiniuSpace, prefix="", limit=1000, marker=marker)
    marker = ret.get('marker', None)
    for item in ret['items']:
        dtime=datetime.datetime.fromtimestamp(item['putTime']/10e6)
        timedelta=dtime-beforetime
        if timedelta.total_seconds()<0:
            todel_file.append(item)
if err is not qiniu.rsf.EOF:
    # 错误处理
    pass

delkeys=[]
for delf in todel_file:
    path_1 = qiniu.rs.EntryPath(qiniuSpace, delf['key'])
    delkeys.append(path_1)
rets, err = qiniu.rs.Client().batch_delete(delkeys)