How to use the nhentai.logger.logger.error function in nhentai

To help you get started, we’ve selected a few nhentai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RicterZ / nhentai / nhentai / cmdline.py View on Github external
logger.info('Cookie saved.')
        exit(0)

    if os.path.exists(os.path.join(constant.NHENTAI_HOME, 'proxy')):
        with open(os.path.join(constant.NHENTAI_HOME, 'proxy'), 'r') as f:
            link = f.read()
            constant.PROXY = {'http': link, 'https': link}

    if args.proxy:
        try:
            if not os.path.exists(constant.NHENTAI_HOME):
                os.mkdir(constant.NHENTAI_HOME)

            proxy_url = urlparse(args.proxy)
            if proxy_url.scheme not in ('http', 'https'):
                logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
            else:
                with open(os.path.join(constant.NHENTAI_HOME, 'proxy'), 'w') as f:
                    f.write(args.proxy)
        except Exception as e:
            logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
            exit(1)

        logger.info('Proxy \'{0}\' saved.'.format(args.proxy))
        exit(0)

    if args.favorites:
        if not constant.COOKIE:
            logger.warning('Cookie has not been set, please use `nhentai --cookie \'COOKIE\'` to set it.')
            exit(1)

    if args.id:
github RicterZ / nhentai / nhentai / parser.py View on Github external
if os.getenv('DEBUG'):
        logger.info('CSRF token is {}'.format(csrf_token))

    login_dict = {
        'csrfmiddlewaretoken': csrf_token,
        'username_or_email': username,
        'password': password,
    }
    resp = request('post', url=constant.LOGIN_URL, data=login_dict)

    if 'You\'re loading pages way too quickly.' in resp.text or 'Really, slow down' in resp.text:
        csrf_token = _get_csrf_token(resp.text)
        resp = request('post', url=resp.url, data={'csrfmiddlewaretoken': csrf_token, 'next': '/'})

    if 'Invalid username/email or password' in resp.text:
        logger.error('Login failed, please check your username and password')
        exit(1)

    if 'You\'re loading pages way too quickly.' in resp.text or 'Really, slow down' in resp.text:
        logger.error('Using nhentai --cookie \'YOUR_COOKIE_HERE\' to save your Cookie.')
        exit(2)
github RicterZ / nhentai / nhentai / parser.py View on Github external
'csrfmiddlewaretoken': csrf_token,
        'username_or_email': username,
        'password': password,
    }
    resp = request('post', url=constant.LOGIN_URL, data=login_dict)

    if 'You\'re loading pages way too quickly.' in resp.text or 'Really, slow down' in resp.text:
        csrf_token = _get_csrf_token(resp.text)
        resp = request('post', url=resp.url, data={'csrfmiddlewaretoken': csrf_token, 'next': '/'})

    if 'Invalid username/email or password' in resp.text:
        logger.error('Login failed, please check your username and password')
        exit(1)

    if 'You\'re loading pages way too quickly.' in resp.text or 'Really, slow down' in resp.text:
        logger.error('Using nhentai --cookie \'YOUR_COOKIE_HERE\' to save your Cookie.')
        exit(2)
github RicterZ / nhentai / nhentai / cmdline.py View on Github external
exit(0)

    if os.path.exists(constant.NHENTAI_LANGUAGE) and not args.language:
        with open(constant.NHENTAI_LANGUAGE, 'r') as f:
            constant.LANGUAGE = f.read()
            args.language = f.read()

    if args.language:
        try:
            if not os.path.exists(constant.NHENTAI_HOME):
                os.mkdir(constant.NHENTAI_HOME)

            with open(constant.NHENTAI_LANGUAGE, 'w') as f:
                f.write(args.language)
        except Exception as e:
            logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
            exit(1)

        logger.info('Default language now is {}.'.format(args.language))
        exit(0)

    if os.path.exists(constant.NHENTAI_PROXY):
        with open(constant.NHENTAI_PROXY, 'r') as f:
            link = f.read()
            constant.PROXY = {'http': link, 'https': link}

    if args.proxy:
        try:
            if not os.path.exists(constant.NHENTAI_HOME):
                os.mkdir(constant.NHENTAI_HOME)

            proxy_url = urlparse(args.proxy)
github RicterZ / nhentai / nhentai / parser.py View on Github external
try:
                page = int(range_str)
                if page <= max_page_num:
                    pages.add(page)
            except ValueError:
                logger.error('page range({0}) is not valid'.format(page_range))
        else:
            try:
                left = int(range_str[:idx])
                right = int(range_str[idx+1:])
                if right > max_page_num:
                    right = max_page_num
                for page in range(left, right+1):
                    pages.add(page)
            except ValueError:
                logger.error('page range({0}) is not valid'.format(page_range))
    
    return list(pages)
github RicterZ / nhentai / nhentai / parser.py View on Github external
else:
            unicode_ = unicode

        if isinstance(tag_name, (str, unicode_)):
            logger.debug('Fetching page {0} for doujinshi with tag \'{1}\''.format(p, tag_name))
            response = request('get', url='%s/%s/%s?page=%d' % (constant.TAG_URL[index], tag_name, sorting, p)).content
            result += _get_title_and_id(response)
        else:
            for i in tag_name:
                logger.debug('Fetching page {0} for doujinshi with tag \'{1}\''.format(p, i))
                response = request('get',
                                   url='%s/%s/%s?page=%d' % (constant.TAG_URL[index], i, sorting, p)).content
                result += _get_title_and_id(response)

        if not result:
            logger.error('Cannot find doujinshi id of tag \'{0}\''.format(tag_name))
            return

    if not result:
        logger.warn('No results for tag \'{}\''.format(tag_name))

    return result
github RicterZ / nhentai / nhentai / parser.py View on Github external
if os.getenv('DEBUG'):
        pages = 1

    page_range_list = range(1, pages + 1)
    if page_range:
        logger.info('page range is {0}'.format(page_range))
        page_range_list = page_range_parser(page_range, pages)

    for page in page_range_list:
        try:
            logger.info('Getting doujinshi ids of page %d' % page)
            resp = request('get', constant.FAV_URL + '?page=%d' % page).content

            result.extend(_get_title_and_id(resp))
        except Exception as e:
            logger.error('Error: %s, continue', str(e))

    return result
github RicterZ / nhentai / nhentai / utils.py View on Github external
def check_cookie():
    response = request('get', constant.BASE_URL).text
    username = re.findall('"/users/\d+/(.*?)"', response)
    if not username:
        logger.error('Cannot get your username, please check your cookie or use `nhentai --cookie` to set your cookie')
    else:
        logger.info('Login successfully! Your username: {}'.format(username[0]))
github RicterZ / nhentai / nhentai / parser.py View on Github external
def favorites_parser(page_range=''):
    result = []
    html = BeautifulSoup(request('get', constant.FAV_URL).content, 'html.parser')
    count = html.find('span', attrs={'class': 'count'})
    if not count:
        logger.error("Can't get your number of favorited doujins. Did the login failed?")
        return []

    count = int(count.text.strip('(').strip(')').replace(',', ''))
    if count == 0:
        logger.warning('No favorites found')
        return []
    pages = int(count / 25)

    if pages:
        pages += 1 if count % (25 * pages) else 0
    else:
        pages = 1

    logger.info('You have %d favorites in %d pages.' % (count, pages))

    if os.getenv('DEBUG'):