Ejemplo n.º 1
0
    def __init__(self):

        self.cow = Cow("t6UadOn0bPkZE_qSFCmqvP1aVGyRGa6fyehGBAq6",
                       "tvOqQBsf6yZEAom95GVSncn1AUoZedQ2PEmRDrdi")
        # print(cow.list_buckets())
        self.current_bucket = None
        self.abs_path = None
        self.parent_path = None
Ejemplo n.º 2
0
    def setUp(self):
        ACCESS_KEY = os.environ['QINIU_ACCESS_KEY']
        SECRET_KEY = os.environ['QINIU_SECRET_KEY']
        bucket = os.environ['QINIU_BUCKET']
        cow = Cow(ACCESS_KEY, SECRET_KEY)
        self.b = cow.get_bucket(bucket)

        for i in range(3):
            with open('sevencow{0}'.format(i), 'w') as f:
                f.write('0000')
Ejemplo n.º 3
0
    def setUp(self):
        ACCESS_KEY = os.environ['QINIU_ACCESS_KEY']
        SECRET_KEY = os.environ['QINIU_SECRET_KEY']
        bucket = os.environ['QINIU_BUCKET']
        cow = Cow(ACCESS_KEY, SECRET_KEY)
        self.b = cow.get_bucket(bucket)

        for i in range(3):
            with open('sevencow{0}'.format(i), 'w') as f:
                f.write('0000')
Ejemplo n.º 4
0
    def setUp(self):
        ACCESS_KEY = os.environ['QINIU_ACCESS_KEY']
        SECRET_KEY = os.environ['QINIU_SECRET_KEY']
        bucket = os.environ['QINIU_BUCKET']
        cow = Cow(ACCESS_KEY, SECRET_KEY)
        self.b = cow.get_bucket(bucket)

        self.files = {'sevencow' + str(i) : i for i in range(2)}
        for k, v in self.files.items():
            with open(k, 'w') as f:
                f.write('v')
Ejemplo n.º 5
0
def upload(filename):
    ACCESS_KEY = 'AHXhPwOlX2Qjn1tAa8e463dJV_o7a2yFsq5SwlOL'
    SECRET_KEY = 'ld18GpYNWJnIeOSq_WJsUbu4pIfepyRVf7huOAzk'
    BUCKET = 'smartlock'
    cow = Cow(ACCESS_KEY, SECRET_KEY)
    b = cow.get_bucket(BUCKET)
    compress(filename)
    filename = filename[0:-4] + '_small.jpeg'
    print filename
    b.put(filename, keep_name=True)
    print 'successful'
Ejemplo n.º 6
0
    def setUp(self):
        ACCESS_KEY = os.environ['QINIU_ACCESS_KEY']
        SECRET_KEY = os.environ['QINIU_SECRET_KEY']
        bucket = os.environ['QINIU_BUCKET']
        cow = Cow(ACCESS_KEY, SECRET_KEY)
        self.b = cow.get_bucket(bucket)

        self.files = {'sevencow' + str(i): i for i in range(2)}
        for k, v in self.files.items():
            with open(k, 'w') as f:
                f.write('v')
Ejemplo n.º 7
0
class AutoUploadPic(object):
    def __init__(self):

        self.cow = Cow("t6UadOn0bPkZE_qSFCmqvP1aVGyRGa6fyehGBAq6",
                       "tvOqQBsf6yZEAom95GVSncn1AUoZedQ2PEmRDrdi")
        # print(cow.list_buckets())
        self.current_bucket = None
        self.abs_path = None
        self.parent_path = None

    def upload(self, path, bucket_name="hexo-picture", keep_name=True):
        '''
        upload picture to qiniu
        '''
        files = []

        self.abs_path = os.path.abspath(path)
        if os.path.isfile(self.abs_path):
            self.parent_path = os.path.dirname(self.abs_path)
            file_name = os.path.basename(self.abs_path)
            files.append(file_name)
        elif os.path.isdir(self.abs_path):
            self.parent_path = self.abs_path
            for file_path in os.listdir(self.abs_path):
                if os.path.isfile(os.path.join(self.abs_path, file_path)):
                    file_name = os.path.basename(file_path)
                    print file_name
                    files.append(file_name)

        # change to picture's parent_path
        os.chdir(self.parent_path)

        print("files:%s" % files)

        self.current_bucket = self.cow.get_bucket(bucket_name)
        for file in files:
            try:
                ret = self.current_bucket.put(file, keep_name=keep_name)
                print("上传成功: %s" % ret)

                self.backup_file(file)
            except CowException as e:
                print("上传失败: file[%s] url[%s] status code[%s] content[%s]" %
                      (file, e.url, e.status_code, e.content))
                continue

    def backup_file(self, file):
        self.bak_path = os.path.join(self.parent_path, ".bak")
        if os.path.isdir(self.bak_path) is False:
            os.mkdir(self.bak_path)
        abs_path = os.path.abspath(file)
        if os.path.isfile(abs_path):
            shutil.move(abs_path, self.bak_path)
        else:
            print("file[%s] is not file" % abs_path)
Ejemplo n.º 8
0
# -*- coding: utf-8 -*-

import sys
import os

from sevencow import CowException
from sevencow import Cow

allFileNum = 0
dirNameList = []

ACCESS_KEY = 'xK4E9mgG3E4aDno7CAXemLMMrns6laJL5AAicJ_O'
SECRET_KEY = 'fsf2oCnVWJPtWZzkr1mou7gAXOSgyCZd6icSGwwk'
BUCKET_NAME = 'wish'

cow = Cow(ACCESS_KEY, SECRET_KEY)
b = cow.get_bucket(BUCKET_NAME)


def printPath(level, path):
    global allFileNum
    '''''
    打印一个目录下的所有文件夹和文件
    '''
    # 所有文件夹,第一个字段是次目录的级别
    dirList = []
    # 所有文件
    fileList = []
    # 返回一个列表,其中包含在目录条目的名称(google翻译)
    files = os.listdir(path)
    # 先添加目录级别
Ejemplo n.º 9
0
from sevencow import Cow

ACCESS_KEY = "zB0oT4SCMtPWhGlNqwn80AelM3xlkZvuyrOA_-AC"
SECRET_KEY = "ME1r6PXfZNNpdQlVp3yd_kS00M0_L8lNm4vbYN7N"
BUCKET = "orange"

cow = Cow(ACCESS_KEY, SECRET_KEY)
b = cow.get_bucket(BUCKET)

print cow.list_buckets()

print "files:"
for f in b.list_files()["items"]:
	print f["key"]

#b.put('thinking-in-go.mp4')

#base_url = qiniu.rs.make_base_url('', key)
#policy = qiniu.rs.GetPolicy()
#private_url = policy.make_request(base_url)