Created
July 11, 2014 15:47
-
-
Save terryoy/f009afe0d23a7aa6686f to your computer and use it in GitHub Desktop.
Shell script to work with Qiniu Cloud Storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
domain_name = '<domain_name>' | |
bucket_name = '<bucket_name>' | |
import qiniu.conf | |
qiniu.conf.ACCESS_KEY = '<qiniu_access_key>' | |
qiniu.conf.SECRET_KEY = '<qiniu_secret_key>' | |
import qiniu.rs, qiniu.rsf | |
import os, urllib, sys | |
rets, err = qiniu.rsf.Client().list_prefix(bucket_name) | |
if not os.path.exists(bucket_name): | |
os.mkdir(bucket_name) | |
for item in rets['items']: | |
fpath = item['key'] | |
print fpath, '...', | |
# create parent folder if needed | |
if not os.path.exists(os.path.dirname(fpath)): | |
os.makedirs(os.path.dirname(fpath)) | |
# test existence | |
if os.path.exists(localpath): | |
print 'existed' | |
else: | |
# download file | |
base_url = qiniu.rs.make_base_url(domain_name, fpath) | |
policy = qiniu.rs.GetPolicy() | |
private_url = policy.make_request(base_url) | |
urllib.urlretrieve(private_url, fpath) | |
print 'downloaded' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment