コード例 #1
0
ファイル: downloader.py プロジェクト: glongzh/vido
def resume_pushing():
    pushing_tasks = Task.objects.filter(status='pushing')
    if pushing_tasks:
        pcs = ByPy()
        for pt in pushing_tasks:
            if pt.item.file_exist():
                push_res = pcs.upload(pt.item.get_item_path(), sanitize(pt.item.title) + '.mp4')
                print 'push_res:' + str(push_res)
                if push_res == 0 or push_res == 60:
                    pt.status = 'pushed'
                    os.remove(pt.item.get_item_path())
                else:
                    pt.status = 'pushing_failed'
                pt.save()
コード例 #2
0
def face_msg(msg):
    image_name = msg.file_name
    print(msg)
    print('接收图片')
    print(image_name)
    print(msg.receive_time)
    imagetime = str(msg.receive_time)
    msg.get_file('/root/weixin/' + msg.file_name)
    path = '/root/weixin/' + msg.file_name

    bp = ByPy()
    bp.upload(localpath=path, remotepath='dir_name', ondup='newcopy')
    print('上传成功' + path)
    print(msg)
コード例 #3
0
ファイル: downloader.py プロジェクト: glongzh/vido
def download():
    cmd_fmt = "{0} -i -R 2 --write-info-json -o '{1}' {2}"
    tasks = Task.objects.filter(Q(status='queue') | Q(status='downloading')).order_by('created_at')

    if tasks:
        pcs = ByPy()
        for t in tasks:
            item = t.item
            cmd = cmd_fmt.format(settings.YTDL_PATH, item.get_item_path(), item.url)
            t.status = 'downloading'
            t.save()
            print 'execute command:' + cmd
            ret = subprocess.call(cmd,shell=True)
            if item.file_exist():
                meta_file_path = os.path.join(settings.SAVE_PATH, item.md5 + '.info.json')
                with open(meta_file_path, 'r') as f:
                    meta = json.load(f)
                    item.title = meta.get('title')
                    item.desc = meta.get('description')
                    item.save()
                t.status = 'success'
                t.save()
                if t.need_pushing:
                    t.status = 'pushing'
                    t.save()
                    push_res = pcs.upload(item.get_item_path(), sanitize(item.title) +'.mp4')
                    print 'push result:' + str(push_res)
                    if push_res == 0:
                        t.status = 'pushed'
                        os.remove(item.get_item_path())
                    else:
                        t.status = 'pushing_failed'
                    t.save()
                
            else:
                t.status = 'failed'
                t.save()
コード例 #4
0
    def uploadFiles(self, allFiles):
        # 百度云存放文件的文件夹名
        dir_name = CONFIG['backupPath']
        totalFileSize = 0  # 文件大小变量
        start = datetime.datetime.now()  # 计时开始

        # 获取一个bypy对象,封装了所有百度云文件操作的方法
        bp = ByPy()
        # 百度网盘创建远程文件夹backup
        bp.mkdir(remotepath=dir_name)

        if isinstance(allFiles, str):
            allFiles = [allFiles]

        for file in allFiles:
            if not os.path.exists(file):
                continue
            fileName = os.path.basename(file)
            filePath = os.path.dirname(file)
            print("正在上传文件:" + file)

            if file != "":
                localpath = filePath if filePath else "."
                bp.upload(localpath=localpath + "/" + fileName,
                          remotepath=str(dir_name),
                          ondup='newcopy')
                print("文件发送完成:本地路径:" + localpath + "/" + fileName + " 远程文件夹:" +
                      dir_name)
                totalFileSize += self.get_FileSize(localpath + "/" + fileName)
            else:
                bp.upload(localpath=fileName,
                          remotepath=dir_name,
                          ondup='newcopy')
                print("文件发送完成:" + fileName + " 远程文件夹:" + dir_name)
                totalFileSize += self.get_FileSize("." + filePath + "/" +
                                                   fileName)
            print("------------------------------------")

        end = datetime.datetime.now()  # 计时结束

        print("上传文件总大小为" + str(totalFileSize) + "MB")
        print("花费时间(s):" + str((end - start).seconds))
        print("\nupload ok")
コード例 #5
0
def besync(path):  # 云盘同步函数 可能因hash导致显示失败,但实际成功。
    dir_name = '监控扩展数据'
    pan = ByPy()
    pan.mkdir(dir_name)
    for file in os.listdir(path):
        if os.path.isdir(file):  # 判断 是文件夹跳过
            continue
        else:
            filename = os.path.join(path, file)  # 文件绝对路径
            pan.upload(localpath=filename,
                       remotepath=dir_name,
                       ondup='newcopy')  # 上传图片