Esempio n. 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)
Esempio n. 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)
Esempio n. 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
Esempio n. 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('所有文件描述设置完毕')
Esempio n. 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()
Esempio n. 6
0
print('开始修复数据库...')
count = 0
helper.init()
for i in range(1, 100):
    helper.get('https://download.csdn.net/my/downloads/{}'.format(i))
    els = helper.find_all('//div[@class="card clearfix"]/div[2]/h3/a')
    hrefs = []
    for el in els:
        href = el.get_attribute('href')
        if href is None:
            continue
        hrefs.append(href)
    for href in hrefs:
        _id = href[href.rfind('/') + 1:]
        is_download = helper.__already_download(_id)
        if not is_download:
            continue
        if db_helper.exist_download(_id):
            continue
        helper.get(href)
        info = helper.__get_download_info()
        info['filename'] = helper.__get_file_name_in_zip_file(info['id'])
        info['url'] = href
        info['qq_num'] = '799329256'
        info['qq_name'] = '菜鸡儿NO.1'
        db_helper.insert_download(info)
        count += 1
        print('插入数据成功({}),ID:{}'.format(count, info['id']))
helper.dispose()
print('修复完成,共修复{}条'.format(count))
Esempio n. 7
0
def __save_to_db(info):
    import db_helper
    if not db_helper.exist_download(info['id']):
        db_helper.insert_download(info)