예제 #1
0
def test():
    try:
        print(helper.check_download_limit(45671948, 623597263))
        # helper.init()
        # print(helper.get_user_info())
        # print(helper.auto_download('https://download.csdn.net/download/cnhww/11153341'))
    finally:
        helper.dispose()
예제 #2
0
def main():
    helper.init('chrome_option_temp')

    # helper.logout()
    helper.auto_login()

    loop = asyncio.get_event_loop()
    loop.run_until_complete(async_export())

    helper.dispose()
예제 #3
0
def test():
    try:
        # print(helper.check_download_limit(45671948, 623597263))
        helper.init()
        # print(helper.get_user_info())
        print(
            helper.auto_download(
                'https://download.csdn.net/download/hfstray/11103359'))
    finally:
        helper.dispose()
예제 #4
0
def test():
    try:
        helper.init()
        print(helper.get_user_info())
        print(
            helper.auto_download(
                'https://download.csdn.net/download/ozhy111/10880596'))
        print(
            helper.auto_download(
                'https://download.csdn.net/download/wjf8882300/10879204'))
        print(
            helper.auto_download(
                'https://download.csdn.net/download/yeyuxingyun/3455948'))
        print(
            helper.auto_download(
                'https://download.csdn.net/download/u013363856/9783561'))
    finally:
        helper.dispose()
예제 #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()
예제 #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))
예제 #7
0
def stop():
    helper.dispose()
    pass
예제 #8
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()