Exemplo n.º 1
0
def test():
    bp=ByPy()
    bp.list("basic_linux/") # or whatever instance methods of ByPy class
    bp.syncup(base_path)
    bp.syndown("/apps/bypy",base_path)
    bp.downfile("basic_linux/wps-office_10.1.0.6634_amd64.deb",externalPaths[0])
    bp.downfile("basic_linux/can_google.crx",externalPaths[0])   
Exemplo n.º 2
0
def compress_and_upload(date):
    date_string = '%04d%02d%02d' % (date.year, date.month, date.day)
    folder_path = 'data/' + date_string
    folder_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               folder_path)
    if not os.path.exists(folder_path):
        LOG.error('%s does not exist', folder_path)
        return
    archive_path = folder_path + '.7z'
    if os.path.exists(archive_path):
        LOG.warning('%s already exists, it is removed first', archive_path)
        os.remove(archive_path)
    LOG.info('Compress and remove %s', folder_path)
    ret = subprocess.run(['7za', 'a', archive_path, folder_path]).returncode
    if ret != 0:
        LOG.error('Compressing %s returns nonzero code %d', folder_path, ret)
        return
    shutil.rmtree(folder_path, ignore_errors=True)
    LOG.info('Upload and remove %s', archive_path)
    bp = ByPy()
    ret = bp.upload(archive_path, 'dshare/data')
    if ret != 0 and ret != 60:
        LOG.error('Bypy upload returns nonzero code %d', ret)
        return
    os.remove(archive_path)
Exemplo n.º 3
0
    def proc(self, config: dict, record_dir: str, danmu_path: str,
             current_state, state_change_time) -> None:
        p = Processor(config, record_dir, danmu_path)
        p.run()

        if config.get('spec', {}).get('uploader', {}).get('record', {}).get(
                'upload_record', False) or config.get('spec', {}).get(
                    'uploader', {}).get('clips', {}).get(
                        'upload_clips', False):
            current_state.value = int(utils.state.UPLOADING_TO_BILIBILI)
            state_change_time.value = time.time()
            try:
                u = Uploader(p.outputs_dir, p.splits_dir, config)
                d = u.upload(p.global_start)
            except Exception as e:
                current_state.value = int(utils.state.ERROR)
                state_change_time.value = time.time()

            if d is None:
                current_state.value = int(utils.state.ERROR)
                state_change_time.value = time.time()
            else:
                if not config.get('spec', {}).get('uploader', {}).get(
                        'record',
                    {}).get('keep_record_after_upload', True) and d.get(
                        "record",
                        None) is not None and not config.get('root', {}).get(
                            'uploader', {}).get('upload_by_edit', False):
                    rc = BiliVideoChecker(d['record']['bvid'], p.splits_dir,
                                          config)
                    rc.start()
                if not config.get('spec', {}).get('uploader', {}).get(
                        'clips',
                    {}).get('keep_clips_after_upload', True) and d.get(
                        "clips",
                        None) is not None and not config.get('root', {}).get(
                            'uploader', {}).get('upload_by_edit', False):
                    cc = BiliVideoChecker(d['clips']['bvid'], p.outputs_dir,
                                          config)
                    cc.start()

        if config.get('root', {}).get('enable_baiduyun', False) and config.get(
                'spec', {}).get('backup', False):
            current_state.value = int(utils.state.UPLOADING_TO_BAIDUYUN)
            state_change_time.value = time.time()
            try:
                from bypy import ByPy
                bp = ByPy()
                bp.upload(p.merged_file_path)
            except Exception as e:
                logging.error('Error when uploading to Baiduyun:' + str(e) +
                              traceback.format_exc())
                current_state.value = int(utils.state.ERROR)
                state_change_time.value = time.time()
                return

        if current_state.value != int(utils.state.LIVE_STARTED):
            current_state.value = int(utils.state.WAITING_FOR_LIVE_START)
            state_change_time.value = time.time()
def main():
    tRange = [dt.datetime(2019, 10, 1), dt.datetime(2019, 10, 31)]
    product = 'cams_nrealtime'
    filename = '{product}_{date}.grib'.format(product=product,
                                              date=tRange[0].strftime('%Y%m'))
    filepath = os.path.join(CONFIG['ECMWF']['DATA_DIR'], filename)
    get_ECMWF_file(tRange, dataset=product, filepath=filepath)

    bp = ByPy()
    bp.upload(filepath, os.path.join(CONFIG['ECMWF']['BDY_DIR'], filename))
Exemplo n.º 5
0
def uploadby(filedir,filename,flag):
    try:
        bp = ByPy()
        if flag:
            bp.mkdir(remotepath = filedir)
        # 上传某一文件到百度云网盘对应的远程文件夹
        # ondup中参数代表复制文件,默认值为'overwrite',指定'newcopy'不会覆盖重复文件
        if os.path.exists(filename):
            bp.upload(localpath= filename, remotepath= filedir, ondup='overwrite')
            os.remove(filename)
    except:logging.info('上传百度云失败')
Exemplo n.º 6
0
def upLoad(t):
    bp = ByPy()
    for l in range(0, len(t) - 1):
        print(os.path.join(os.getcwd(), "tsdir", t[l]))
        try:
            bp.upload(localpath=os.path.join(os.getcwd(), "tsdir", t[l]),
                      remotepath='bypy')
            print('上传完毕!')
            documentDelete(os.path.join(os.getcwd(), "tsdir", t[l]))
        except Exception as e:
            print(e)
Exemplo n.º 7
0
 def uploadApi(self, uploadFilepath):
     uploadFilename = os.path.basename(uploadFilepath)
     uploadFilenameSplit = os.path.basename(uploadFilepath).rstrip(
         '.flv').split('_')
     roomid = uploadFilenameSplit[-1]
     recordDate = uploadFilenameSplit[0]
     bp = ByPy(deletesource=self.delAfterUpload, debug=True)
     if bp.upload(uploadFilepath,
                  f'{roomid}/{recordDate}/{uploadFilename}') != 0:
         if self.forceDelAfterUpload and os.path.isfile(uploadFilepath):
             os.remove(uploadFilepath)
         raise Exception('upload fail.')
Exemplo n.º 8
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')  # 上传图片
Exemplo n.º 9
0
 def __init__(self, config):
     self.config = config
     self.prev_live_status = False
     self.current_state = Value('i',
                                int(utils.state.WAITING_FOR_LIVE_START))
     self.state_change_time = Value('f', time.time())
     if self.config.get('root', {}).get('enable_baiduyun', False):
         from bypy import ByPy
         _ = ByPy()
     self.bl = BiliLive(self.config)
     self.blr = None
     self.bdr = None
Exemplo n.º 10
0
def uploadby(filedir, filename, flag):
    try:
        bp = ByPy()
        if flag:
            bp.mkdir(remotepath=filedir)
        filename = os.path.join('./danmu', filename)
        if os.path.exists(filename):
            bp.upload(localpath=filename,
                      remotepath=filedir,
                      ondup='overwrite')
            os.remove(filename)
    except:
        print('fail')
Exemplo n.º 11
0
def yunpan(upload_dir, build_count):
    pattren = '(.*-{}.apk|.*-signed.apk)'.format(build_count)
    bp = ByPy(configdir='C:\\Users\\Administrator\\.bypy',
              processes=5,
              incregex=pattren)
    #显示网盘使用信息
    bp.info()
    #显示上传日志信息
    bp.verbose = True
    #同步上传
    bp.syncup(localdir=upload_dir, remotedir=build_count)
    #打印云盘目录
    bp.ls(build_count)
Exemplo n.º 12
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)
Exemplo n.º 13
0
def getbdlist():
    bp = ByPy() 
    f_handler= sys.stdout
    f=open('blist', 'w',encoding='utf-8') 
    sys.stdout=f 
    bp.list(u'youtube/','$t $f')  
    sys.stdout =f_handler 
    f.close()
    fs=[]
    with open('blist', 'r',encoding='utf-8') as rf:
         blist= rf.readlines()
         fs =[l[l.find('F ')+2:-1]for l in blist if l[:1]=='F']

    return fs
Exemplo n.º 14
0
def record_start_stop():
    global record_enable, record_flag, record_jud_flag, record_jud, record, start_time, tone_list, tone_flag, ten_sec_flag
    record_jud_flag = 0
    record_flag = (-1) * record_flag
    if record_flag == -1:
        print("record start!")
        noti_rec_start.play(0)
        record = numpy.zeros(shape=[441000, 2], dtype=numpy.int16)
        ten_sec_flag = 1  # to extend reacord with 0
        start_time = time.time()
        record_jud.cancel()
    elif record_flag == 1:
        noti_rec_stop.play(0)
        print("saving...")
        zero_num = 0
        i = 1
        while True:
            if (record[len(record) - i] == record[0]).any():
                zero_num += 1
                i += 1
            else:
                break
        record = record[:len(record) - 1 - zero_num]

        now = time.time()
        now_time = time.strftime("%Y%m%d_%H%M%S")
        path = (now_time + ".wav")
        wavfile.write(path, 44100, record)
        print("local saved!")

        proc = subprocess.Popen(['ping', 'www.baidu.com'],
                                stdout=subprocess.PIPE)
        time.sleep(2)
        proc.kill()
        result = proc.stdout.read().decode()
        if '64 bytes' in result:
            bp = ByPy()
            bp.mkdir(remotepath='music')
            bp.upload(localpath=path, remotepath='music', ondup='newcopy')
            print("uploaded!")
        else:
            print("network disconnected!")

    record_jud.cancel()
    record = numpy.zeros(shape=[441000, 2], dtype=numpy.int16)
Exemplo n.º 15
0
def upload_dir(local_path, remote_path):
    print('开始上传文件:%s' % (local_path.split('\\')[-1]))
    start = datetime.datetime.now()  # 计时开始
    bp = ByPy()
    if remote_path:
        bp.mkdir(remotepath=remote_path)
    if bp.upload(localpath=local_path, remotepath=remote_path,
                 ondup='newcopy'):
        end = datetime.datetime.now()  # 计时结束
        dir_size = get_FileSize(local_path)
        logger.info(
            "文件发送完成:本地路径:%s,远程文件夹:%s 大小:%sMB,花费时间%s" %
            (local_path, remote_path, dir_size, str((end - start).seconds)))
        if os.path.exists(local_path):  # 如果文件存在
            # 删除文件,可使用以下两种方法。
            os.remove(local_path)
            logger.info('删除本地文件')
    else:
        logger.info('上传百度云失败')
Exemplo n.º 16
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")
Exemplo n.º 17
0
def proc(config: dict, record_dir: str, danmu_path: str) -> None:
    p = Processor(config, record_dir, danmu_path)
    p.run()
    u = Uploader(p.outputs_dir, p.splits_dir, config)
    d = u.upload(p.global_start)
    if not config['spec']['uploader']['record'][
            'keep_record_after_upload'] and d.get("record", None) is not None:
        rc = BiliVideoChecker(d['record']['bvid'], p.splits_dir, config)
        rc_process = Process(target=rc.check)
        rc_process.start()
    if not config['spec']['uploader']['clips'][
            'keep_clips_after_upload'] and d.get("clips", None) is not None:
        cc = BiliVideoChecker(d['clips']['bvid'], p.outputs_dir, config)
        cc_process = Process(target=cc.check)
        cc_process.start()
    if config['root']['enable_baiduyun'] and config['spec']['backup']:
        from bypy import ByPy
        bp = ByPy()
        bp.upload(p.merged_file_path)
Exemplo n.º 18
0
def face_msg(msg):
    msg1 = msg
    msg2 = msg
    print(msg2)
    print(msg2.receive_time)
    msg2 = str(msg2.receive_time) + str(msg2)
    save('f:\\imag\\xiaoxi.txt', msg2)

    image_name = msg1.file_name
    print('接收图片')
    print(image_name)
    print(msg1.receive_time)
    imagetime = str(msg1.receive_time)
    msg1.get_file('F:\\imag\\' + msg1.file_name)
    path = 'F:\\imag\\' + msg1.file_name

    bp = ByPy()
    bp.upload(localpath=path, remotepath='dir_name', ondup='newcopy')
    bp.upload(localpath='f:\\imag\\xiaoxi.txt',
              remotepath='dir_name',
              ondup='overwrite')
    print('上传成功' + path + 'f:\\imag\\xiaoxi.txt')
Exemplo n.º 19
0
def plugin_remote(msg, ttext):
    cmdret = ''
    try:
        cmdret = ttext[2:]
        if ttext.startswith('上传'):
            bp = ByPy()
            bdy_initdir(bp)
            cmdret = '本地文件:\r\n' + '\r\n'.join(bdy_upload(bp, ttext[2:]))
            cmdret += ' 成功'
        if ttext.startswith('下载'):
            cmdret += ' 暂不支持'
        if ttext.startswith('列表'):
            cmdret = '本地文件:\r\n' + '\r\n'.join(local_list(ttext[2:]))
        if ttext.startswith('命令'):
            cmdret = '本地命令:\r\n' + ' '.join(local_run(ttext[2:]))
    except Exception as e:
        import traceback
        msg.reply('操作错误:%s\r\n%s' % (str(repr(e)), traceback.format_exc()))
        cmdret = str(repr(e))

    if len(cmdret) > 0:
        msg.reply('%s %s' % (ttext[:2], cmdret))
Exemplo n.º 20
0
def upload_video(dianshiju_url, remote_name='烈火如歌', init_index=9):
    #获取所有集的链接
    data = urllib.request.urlopen(dianshiju_url).read()
    data = data.decode('utf-8', 'ignore')
    pattern1 = 'a class="sn" href="(.*?)s=[a-zA-Z0-9]*" data-from'
    all_url = re.compile(pattern1).findall(data)
    # 创建文件夹
    bp = ByPy()
    #bp.mkdir(remotepath='视频/%s' % remote_name)
    #下载所有剧集
    for i in range(init_index, len(all_url)):
        print("下载第%d集..." % (i + 1))
        source_url = 'http:%sspm=a2h0j.11185381.listitem_page1.5!%d~A' % (
            all_url[i], i + 1)
        if (not os.path.exists('C:\\Users\\T\\Downloads\\%s' % remote_name)):
            os.mkdir('C:\\Users\\T\\Downloads\\%s' % remote_name)
        filename = 'C:\\Users\\T\\Downloads\\%s\\%d.mp4' % (remote_name, i + 1)
        get_video(source_url, filename=filename)
        bp.upload(localpath='C:\\Users\\T\\Downloads\\%s\\%d.mp4' %
                  (remote_name, i + 1),
                  remotepath='/视频/%s' % remote_name,
                  ondup='newcopy')
        print('上传第%d集完毕' % (i + 1))
Exemplo n.º 21
0
def upload_Bdyun(folderName):
    bp = ByPy()
    print('正在创建存储文件夹'.center(74, '-'))
    bp.mkdir(remotepath=folderName)  # 在网盘中新建目录

    print('开始上传图片'.center(76, '-'))
    bp.upload(localpath=folderName, remotepath=folderName,
              ondup='newcopy')  # 将本地文件上传到百度云盘中

    print('开始上传压缩包'.center(76, '-'))
    bp.upload(localpath=folderName + '.rar',
              remotepath=folderName,
              ondup='newcopy')  # 将本地文件上传到百度云盘中

    print('开始上传网页'.center(76, '-'))
    bp.upload(localpath='{}.html'.format(folderName),
              remotepath=folderName,
              ondup='newcopy')  # 将本地文件上传到百度云盘中

    print('上传完毕!'.center(76, '-'))

    os.remove('[附件]' + folderName + '.rar')
    os.remove(folderName + '.rar')
    os.remove(folderName + '.html')
Exemplo n.º 22
0
        level=utils.get_log_level(all_config),
        format=
        '%(asctime)s %(thread)d %(threadName)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
        datefmt='%a, %d %b %Y %H:%M:%S',
        handlers=[
            logging.FileHandler(os.path.join(
                all_config.get('root', {}).get('logger',
                                               {}).get('log_path', "./log"),
                logfile_name),
                                "a",
                                encoding="utf-8")
        ])
    utils.init_data_dirs(all_config.get('root', {}).get('data_path', "./"))
    if all_config.get('root', {}).get('enable_baiduyun', False):
        from bypy import ByPy
        bp = ByPy()

    runner_dict = {}
    for spec_config in all_config.get('spec', []):
        config = {'root': all_config.get('root', {}), 'spec': spec_config}
        tr = MainThreadRunner(config)
        tr.setDaemon(True)
        runner_dict[spec_config['room_id']] = tr

    for tr in runner_dict.values():
        tr.start()
        time.sleep(10)

    while True:
        old_config = all_config
        try:
Exemplo n.º 23
0
def run():
    bp = ByPy()
    bp.syncup(localdir=u'', remotedir=u'youtube/', deleteremote=False)
Exemplo n.º 24
0
from io import StringIO
from bypy import ByPy
import sys
import logging

if len(sys.argv) <= 1:
    logging.error("No filename specified")
    exit()

fn = sys.argv[1]
folder = "/"

if len(sys.argv) > 2:
    folder = sys.argv[2] + folder

bp = ByPy(verbose=1, debug=True)
bp.upload(fn, folder + fn)

sys.stdout = mystdout = StringIO()

bp.debug = False
bp.verbose = 0
bp.meta(folder + fn, '$i')

sys.stdout = sys.__stdout__

mystdout.seek(0)
mystdout.readline()
fid = mystdout.readline()

print("fid:\"" + str(fid).strip() + "\"")
Exemplo n.º 25
0
For RaspberryPi
it will capture a picture from camera on RaspberryPi every 1(default) minute,
and upload it to Baidu netdisk
Make sure you can use bypy normally.(https://github.com/houtianze/bypy)
By bms
'''
import os
from time import sleep
from datetime import datetime, timedelta
from picamera import PiCamera
from bypy import ByPy


def wait(delay_minute=1):
    next_time = (datetime.now() + timedelta(minutes=delay_minute)).replace(
        second=0, microsecond=0)
    delay = (next_time - datetime.now()).seconds
    sleep(delay)


by = ByPy()
camera = PiCamera()
camera.start_preview()
wait()

for filename in camera.capture_continuous('img{timestamp:%Y-%m-%d-%H-%M}.jpg'):
    print('capture %s' % filename)
    by.upload(filename)
    os.remove(filename)
    wait()
Exemplo n.º 26
0
 def upload_data(path):
     bp = ByPy()
     bp.upload(path)
     #bp.cleancache()
     os.remove(path)
     shutil.rmtree(BACKUP_FOLDER)
Exemplo n.º 27
0
import requests
from bypy import ByPy

bypy = ByPy()


def crawl(targetId):
    print("-- target " + str(targetId))
    # 下载网页
    rsp = requests.get("https://boxueio.com/series/antlr-basics/episode/" +
                       str(targetId))
    print(rsp.content)

    # 找出视频描述json

    # 解析出视频地址

    # 下载视频到指定目录

    # 转码压缩为mp4

    # 同步到百度网盘


def main():
    print(" --- hello ---")
    # bypy.list()
    # bypy.mkdir("iPython/test1")

    for index in range(1, 2):
        try:
Exemplo n.º 28
0
def upload(local, remote):
    #os.chdir(local)
    bp = ByPy()
    bp.list()
    bp.syncup(local, remote)
    print "fineshed!!!"
Exemplo n.º 29
0
# encoding:utf-8

from bypy import ByPy
bp = ByPy()
bp.list()
Exemplo n.º 30
0
                "https://exhentai\.org/g/[0-9]{1,8}/[A-Za-z0-9]{10}/")):
        if "href" in link.attrs:
            link2 = link.attrs["href"]
            hlist.append(link2.split("/")[4:6])
    if eoltoken in hlist:
        eol = hlist.index(eoltoken)
        hlist = hlist[eol + 1:len(hlist)]
    eollist = hlist[-1]
    print(hlist)
    req = {"method": "gdata", "gidlist": hlist, "namespace": 1}
    recl = json.loads(json.dumps(requests.post(
        "https://api.e-hentai.org/api.php",
        data=json.dumps(req, ensure_ascii=False).encode("utf-8")).json(),
                                 ensure_ascii=False),
                      encoding="UTF-8")['gmetadata']
    for obj in recl:
        with open(str(uuid.uuid4()) + ".json", "w", encoding="UTF-8") as f:
            json.dump(obj, f, ensure_ascii=False)
    hlistc = hlistc + 1
    if hlistc > 4:
        time.sleep(5)
        hlistc = 0
    hlist.clear()
for f in glob.glob("*.json"):
    with open(f, "rb") as inf:
        merge.append(json.load(inf))
with open("fin.json", "w", encoding="UTF-8") as out:
    json.dump(merge, out, ensure_ascii=False, sort_keys=True)
ByPy().quota()
ByPy().upload("fin.json", "fin.json", "overwrite")