Beispiel #1
0
def auto_sync_loop():
    folder_id = lzy.list_dir()['folder_list'][folder_name]
    print('拉取文件列表...')
    list_dir = lzy.list_dir(folder_id)
    cloud_files = list_dir['file_list']
    cloud_files.update(list_dir['folder_list'])
    print('拉取文件列表完成。')
    while True:
        local_files = os.listdir(config.zip_save_path)
        for lf in local_files:
            f_path = os.path.join(config.zip_save_path, lf)
            f_size = os.path.getsize(f_path)
            f_id = lf[:-4]
            # 文件的修改时间小于10分钟则不进行上传
            if time.time() - os.path.getmtime(f_path) < 600:
                continue
            # 文件大小超过 99MB 时不上传
            # lf_size = os.path.getsize(f_path)
            # if lf_size > 99 * 1024 * 1024:
            #    continue
            if lf not in cloud_files and db_helper.exist_download(f_id):
                print(f'开始上传文件[{lf}]({f_size}b)...')
                d = db_helper.get_download(f_id)
                desc = d.title + "\n" + d.description
                if len(desc) > 159:
                    desc = desc[0:156] + "..."
                result = lzy.upload2(f_path, folder_id, desc)
                db_helper.set_download_url(f_id, result['share_url'])
                os.remove(f_path)
                cloud_files[lf] = result['file_id']
                print("上传完成!")
                break
        time.sleep(2)
Beispiel #2
0
def build_url(_id):
    if db_helper.exist_download(_id):
        dl = db_helper.get_download(_id)
        if dl.download_url is not None and dl.download_url != '':
            return dl.download_url

    url = '{}{}.zip'.format(config.download_server_url, _id)
    return short_url.get(url)
Beispiel #3
0
def __already_download(_id):
    import db_helper
    if db_helper.exist_download(_id) and db_helper.get_download(
            _id).download_url is not None:
        return True
    zip_path = os.path.join(zip_save_path, "{0}.zip".format(_id))
    if os.path.exists(zip_path):
        file_name = __get_file_name_in_zip_file(_id)
        if file_name is not None and not file_name.endswith('.crdownload'):
            return True
    return False
Beispiel #4
0
def set_all_desc():
    folder_id = lzy.list_dir()['folder_list'][folder_name]
    print('拉取文件列表...')
    cloud_files = lzy.list_dir(folder_id)['file_list']
    print('拉取文件列表完成。')
    i = 0
    for (cf_name, cf_id) in cloud_files.items():
        db_id = cf_name[:-4]
        i = i + 1
        if not db_helper.exist_download(db_id):
            continue
        d = db_helper.get_download(db_id)
        desc = d.title + "\n" + d.description
        if len(desc) > 159:
            desc = desc[0:156] + "..."
        suc = lzy.modify_description(cf_id, desc)
        print(f'[{i}/{len(cloud_files)}]设置{db_id}描述结果:{suc}')
    print('所有文件描述设置完毕')
Beispiel #5
0
async def handle_msg_group(context):
    global last_cmd
    global last_arg_str
    global last_arg_int
    message = context['message']

    if config.need_at_me:
        if not is_at_me(message):
            return
    if is_at_me(message):
        message = rm_at_me(message)

    message = message.strip()
    cmd_args = message.split(' ')
    cmd = cmd_args[0]
    args = cmd_args[1:] if len(cmd_args) > 1 else []

    def is_all_number(_str: str):
        if _str is None or _str == '':
            return False
        for a in _str:
            if not '0' <= a <= '9':
                return False
        return True

    arg_int = int(args[0]) if len(args) > 0 and is_all_number(args[0]) else 0
    arg_int_2 = int(args[1]) if len(args) > 1 and is_all_number(args[1]) else 0
    arg_str = args[0] if len(args) > 0 else ''

    qq_num = str(context['sender']['user_id'])
    qq_name = context['sender']['nickname']
    if 'card' in context['sender'] and context['sender']['card'] != '':
        qq_name = context['sender']['card']
    qq_group = '-1'
    if 'group_id' in context:
        qq_group = str(context['group_id'])

    if cmd == '-help' or cmd == '-?':
        msg = '● 个人信息 -personal'
        msg += '\n● 排行榜  -rank [index]'
        msg += '\n● 查询文件 -find [keyword]'
        msg += '\n● 文件信息 -info [id]'
        msg += '\n● 更多信息 -more'
        msg += sep_s()
        msg += '\n* 输入CSDN下载页链接下载'
        msg += source_code_tail()
        msg += donate_tail()
        msg += export_tail()
        last_cmd = cmd
        await bot.send(context, msg)

    if cmd == '-user':
        await bot.send(context, '查询用户信息中...')
        helper.init()
        info = helper.get_user_info()
        helper.dispose()
        if info is None:
            msg = '获取用户信息失败!'
        else:
            msg = '{}'.format(info['name'])
            if info['vip']:
                msg += '【VIP】'
                msg += '\n剩余次数:{}次'.format(info['remain'])
                msg += '\n有效期至:{}'.format(info['date'][:10])
            else:
                msg += '\n剩余积分:{}积分'.format(info['remain'])
        await bot.send(context, msg)

    if cmd == '-rank':
        result = db_helper.rank_qq(arg_int)
        msg = build_rank_msg(result, arg_int)
        last_cmd = cmd
        last_arg_int = arg_int
        await bot.send(context, msg)

    if cmd == '-find':
        result = db_helper.find_all(arg_str, arg_int_2)
        count = db_helper.count_all(arg_str)
        msg = build_find_msg(result, count, arg_int_2)
        last_cmd = cmd
        last_arg_str = arg_str
        last_arg_int = arg_int_2
        await bot.send(context, msg)

    if cmd == '-info':
        result = db_helper.get_download(arg_int)
        if result is not None:
            msg = build_download_info(result)
            last_cmd = cmd
            last_arg_str = arg_str
            last_arg_int = arg_int
            await bot.send(context, msg)
        else:
            await bot.send(context, '文件不存在。')

    if cmd == '-donors':
        msg = build_donors(arg_int)
        last_cmd = cmd
        last_arg_int = arg_int
        await bot.send(context, msg)

    if cmd == '-personal':
        msg = build_personal(qq_num, qq_group, qq_name)
        await bot.send(context, msg)

    if cmd == '-more':
        if last_cmd == '-find':
            last_arg_int += 10
            result = db_helper.find_all(last_arg_str, last_arg_int)
            count = db_helper.count_all(last_arg_str)
            msg = build_find_msg(result, count, last_arg_int)
            await bot.send(context, msg)
        if last_cmd == '-rank':
            last_arg_int += 10
            result = db_helper.rank_qq(last_arg_int)
            msg = build_rank_msg(result, last_arg_int)
            await bot.send(context, msg)
        if last_cmd == '-info':
            result = db_helper.get_download(last_arg_int)
            if result is not None:
                msg = build_download_detail_info(result)
                await bot.send(context, msg)
        if last_cmd == '-donors':
            last_arg_int += 10
            msg = build_donors(last_arg_int)
            await bot.send(context, msg)
        if last_cmd == '-help' or last_cmd == '-?':
            msg = '● 用户信息 -user'
            msg += '\n● 捐赠名单 -donors'
            msg += sep_s()
            msg += '\n* 输入CSDN下载页链接下载'
            msg += source_code_tail()
            msg += donate_tail()
            msg += export_tail()
            await bot.send(context, msg)

    download_id = find_csdn_download_id(context['message'])
    if download_id is not None:
        if helper.__already_download(download_id) and db_helper.exist_download(
                download_id):
            msg = build_download_info(db_helper.get_download(download_id))
            await bot.send(context, msg)
            return

    download_url = find_csdn_download_url(context['message'])
    if download_url is not None:
        can_download, msg = helper.check_download_limit(qq_num, qq_group)
        if not can_download:
            await bot.send(context, msg)
            return

        if helper.is_busy():
            await bot.send(context, '资源正在下载中,请稍后...')
            return
        await bot.send(context, '开始下载...')
        try:
            helper.init()
            download_info = helper.auto_download(download_url, qq_num, qq_name,
                                                 qq_group)
            msg = download_info['message']
            if download_info['success']:
                result = db_helper.get_download(download_info['info']['id'])
                msg = build_download_info(result)
                last_cmd = '-info'
                last_arg_int = int(result.id)
            elif donate_tail() != '':
                msg += sep_s()
                msg += donate_tail()
            await bot.send(context, msg)
        finally:
            helper.dispose()
Beispiel #6
0
async def handle_msg(context):
    # 下面这句等价于 bot.send_private_msg(user_id=context['user_id'], message='你好呀,下面一条是你刚刚发的:')
    """
    try:
         await bot.send(context, '你好呀,下面一条是你刚刚发的:')
     except ApiError:
         pass
    """
    global last_cmd
    global last_arg_str
    global last_arg_int
    message = context['message']
    if message.startswith('@{}'.format(config.default_qq_name)):
        message = message[4:]
    message = message.strip()
    cmd_args = message.split(' ')
    cmd = cmd_args[0]
    args = cmd_args[1:] if len(cmd_args) > 1 else []

    def is_all_number(_str: str):
        if _str is None or _str == '':
            return False
        for a in _str:
            if not '0' <= a <= '9':
                return False
        return True

    arg_int = int(args[0]) if len(args) > 0 and is_all_number(args[0]) else 0
    arg_int_2 = int(args[1]) if len(args) > 1 and is_all_number(args[1]) else 0
    arg_str = args[0] if len(args) > 0 else ''

    if cmd == '-help' or cmd == '-?':
        msg = '● 用户信息 -user'
        msg += '\n● 排行榜  -rank [index]'
        msg += '\n● 查询文件 -find [keyword]'
        msg += '\n● 文件信息 -info [id]'
        msg += '\n● 更多信息 -more'
        msg += '\n' + '-' * 38
        msg += '\n* 直接输入CSDN下载页链接即可下载'
        msg += '\n* 大黄鸭源码 http://t.cn/EK5Q58Y'
        await bot.send(context, msg)

    if cmd == '-user':
        await bot.send(context, '查询用户信息中...')
        helper.init()
        info = helper.get_user_info()
        helper.dispose()
        if info is None:
            msg = '获取用户信息失败!'
        else:
            msg = '{}'.format(info['name'])
            if info['vip']:
                msg += '【VIP】'
                msg += '\n剩余次数:{}次'.format(info['remain'])
                msg += '\n有效期至:{}'.format(info['date'][:10])
            else:
                msg += '\n剩余积分:{}积分'.format(info['remain'])
        await bot.send(context, msg)

    if cmd == '-rank':
        result = db_helper.rank_qq(arg_int)
        msg = build_rank_msg(result, arg_int)
        last_cmd = cmd
        last_arg_int = arg_int
        await bot.send(context, msg)

    if cmd == '-find':
        result = db_helper.find_all(arg_str, arg_int_2)
        count = db_helper.count_all(arg_str)
        msg = build_find_msg(result, count, arg_int_2)
        last_cmd = cmd
        last_arg_str = arg_str
        last_arg_int = arg_int_2
        await bot.send(context, msg)

    if cmd == '-info':
        result = db_helper.get_download(arg_int)
        if result is not None:
            msg = build_download_info(result)
            last_cmd = cmd
            last_arg_str = arg_str
            last_arg_int = arg_int
            await bot.send(context, msg)
        else:
            await bot.send(context, '文件不存在。')

    if cmd == '-more':
        if last_cmd == '-find':
            last_arg_int += 10
            result = db_helper.find_all(last_arg_str, last_arg_int)
            count = db_helper.count_all(arg_str)
            msg = build_find_msg(result, count, last_arg_int)
            await bot.send(context, msg)
        if last_cmd == '-rank':
            last_arg_int += 10
            result = db_helper.rank_qq(last_arg_int)
            msg = build_rank_msg(result, last_arg_int)
            await bot.send(context, msg)
        if last_cmd == '-info':
            result = db_helper.get_download(last_arg_int)
            if result is not None:
                msg = build_download_detail_info(result)
                await bot.send(context, msg)

    download_url = find_csdn_download_url(context['message'])
    if download_url is not None:
        if helper.is_busy():
            await bot.send(context, '资源正在下载中,请稍后...')
            return
        await bot.send(context, '开始下载...')
        try:
            helper.init()
            qq_num = context['sender']['user_id']
            qq_name = context['sender']['nickname']
            if 'card' in context['sender'] and context['sender']['card'] != '':
                qq_name = context['sender']['card']
            download_info = helper.auto_download(download_url, qq_num, qq_name)
            msg = download_info['message']
            if download_info['success']:
                result = db_helper.get_download(download_info['info']['id'])
                msg = build_download_info(result)
                last_cmd = '-info'
                last_arg_int = int(result.id)
            await bot.send(context, msg)
        finally:
            helper.dispose()