How to use the build.lib.pikax.util.log function in build

To help you get started, we’ve selected a few build 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 Redcxx / Pikax / build / lib / pikax / items.py View on Github external
bookmark_ids = []
        try:
            while curr_page < last_page:
                curr_page += 1
                params['p'] = curr_page
                res = util.req(session=self.session, url=self._bookmarks_url, params=params)
                res_json = util.json_loads(res.content)
                bookmark_ids += [illust['id'] for illust in res_json['bookmarks']]
                if limit != None:
                    if len(bookmark_ids) > limit:
                        bookmark_ids = util.trim_to_limit(items=bookmark_ids, limit=limit)
                        break
                last_page = res_json['lastPage']
        except (ReqException, json.JSONDecodeError, KeyError) as e:
            util.log(str(e), error=True)
            util.log('Failed to get bookmarks from id:', self.id)

        bookmarks = util.generate_artworks_from_ids(bookmark_ids)
        return bookmarks
github Redcxx / Pikax / build / lib / pikax / items.py View on Github external
try:
            while curr_page < last_page:
                curr_page += 1

                params['p'] = curr_page
                res = util.req(session=self.session, url=self._content_url, params=params)
                res_json = util.json_loads(res.content)
                items_ids += [illust['id'] for illust in res_json['illusts']]
                if limit != None:
                    if len(items_ids) > limit:
                        items_ids = util.trim_to_limit(items=items_ids, limit=limit)
                        break
                last_page = res_json['lastPage']
        except (ReqException, json.JSONDecodeError, KeyError) as e:
            util.log(str(e), error=True)
            util.log('Failed to get ' + type + ' from id:', self.id)

        artworks = util.generate_artworks_from_ids(items_ids)
        return artworks
github Redcxx / Pikax / build / lib / pikax / items.py View on Github external
file_name = util.clean_filename(folder) + '/' + file_name

            if os.path.isfile(file_name):
                util.log(pic_detail, 'skipped.', 'Reason:', file_name, 'already exists or access not granted')
                skipped = True
                curr_page += 1
                continue

            try:
                err_msg = pic_detail + ' Failed'
                original_pic_respond = util.req(type='get', url=url, headers=self._headers, err_msg=err_msg, log_req=False)
                with open(file_name, 'wb') as file:
                    file.write(original_pic_respond.content)
                    util.log(pic_detail + ' OK', inform=True, start=settings.CLEAR_LINE, end='\r')
            except ReqException as e:
                util.log(str(e), error=True, save=True)
                util.log(pic_detail + ' FAILED', inform=True, save=True, start=settings.CLEAR_LINE)
                success = False

            curr_page += 1

        if results_dict:
            if skipped:
                results_dict['skipped'] += 1
            elif success:
                results_dict['success'] += 1
            else:
                results_dict['failed'] += 1
github Redcxx / Pikax / build / lib / pikax / api / webclient.py View on Github external
# cookies exists
        util.log(f'Cookie file found: {self.cookies_file}, attempt to login with local cookie')
        try:
            with open(self.cookies_file, 'rb') as f:
                local_cookies = pickle.load(f)
                self._session.cookies = local_cookies
            if self._check_is_logged():
                util.log('Logged in successfully with local cookies', inform=True)
                return
            else:
                os.remove(self.cookies_file)
                util.log('Removed outdated cookies', inform=True)
        except pickle.UnpicklingError as e:
            os.remove(self.cookies_file)
            util.log('Removed corrupted cookies file, message: {}'.format(e))

        # local cookies failed
        raise LoginError('Login with cookies failed')
github Redcxx / Pikax / build / lib / pikax / api / webclient.py View on Github external
def _local_cookies_login(self):

        if not os.path.exists(self.cookies_file):
            raise LoginError('Local Cookies file not found')

        # cookies exists
        util.log(f'Cookie file found: {self.cookies_file}, attempt to login with local cookie')
        try:
            with open(self.cookies_file, 'rb') as f:
                local_cookies = pickle.load(f)
                self._session.cookies = local_cookies
            if self._check_is_logged():
                util.log('Logged in successfully with local cookies', inform=True)
                return
            else:
                os.remove(self.cookies_file)
                util.log('Removed outdated cookies', inform=True)
        except pickle.UnpicklingError as e:
            os.remove(self.cookies_file)
            util.log('Removed corrupted cookies file, message: {}'.format(e))

        # local cookies failed
        raise LoginError('Login with cookies failed')
github Redcxx / Pikax / build / lib / pikax / items.py View on Github external
def factory(id):
        """return a Artwork Object given its id, None if failed

        **Returns**
        :return: Artwork of that id
        :rtype: Artwork
        """
        try:
            return Artwork(id)
        except ArtworkError as e:
            util.log(str(e), error=True, save=True)
            return None
github Redcxx / Pikax / build / lib / pikax / items.py View on Github external
def _get_token(self):
        try:
            res = util.req(url=self._settings_url, session=self.session)
            tt_result = re.search(r'name="tt" value="(.*?)"', res.text)
            if tt_result:
                tt = tt_result.group(1)
                util.log('successfully retrieved user token:', tt)
                return tt
            else:
                raise UserError('Failed to find user token in respond')
        except ReqException as e:
            raise UserError('Failed to retrieve user token')
github Redcxx / Pikax / build / lib / pikax / api / webclient.py View on Github external
def _get_postkey(self):
        try:
            pixiv_login_page = util.req(session=self._session, url=self._post_key_url)
            post_key = re.search(r'post_key" value="(.*?)"', pixiv_login_page.text).group(1)
            util.log(f'Post key successfully retrieved: {post_key}')
            return post_key
        except (ReqException, AttributeError) as e:
            raise LoginError(f'Failed to find post key: {e}')
github Redcxx / Pikax / build / lib / pikax / items.py View on Github external
**Parameters**
        :param limit:
            limit the amount of bookmarks found, if exceed
        :type limit:
            int or None

        :return: the results of attempting to retrieve this user's bookmarks
        :rtype: PixivResult Object

        """
        util.log('Getting bookmarks from id:', self.id)
        if self.has_bookmarks :
            self.bookmark_artworks = self._get_bookmark_artworks(limit=limit)
        else:
            util.log('User with id:', self.id, 'has no bookmarks')
            self.bookmark_artworks = []

        util.log('Found', len(self.bookmark_artworks), 'bookmarks')

        folder = settings.USER_BOOKMARKS_DOWNLOAD_FOLDER.format(title=self.title)
        result = PixivResult(self.bookmark_artworks, folder=folder)
        return result
github Redcxx / Pikax / build / lib / pikax / api / webclient.py View on Github external
'password': password,
            'pixiv_id': username,
            'post_key': postkey,
        }
        login_params = {
            'lang': 'en'
        }

        util.log('Sending requests to attempt login ...')

        try:
            util.req(req_type='post', session=self._session, url=self._login_url, data=data, params=login_params)
        except ReqException as e:
            raise LoginError(f'Failed to send login request: {e}')

        util.log('Login request sent to Pixiv')
        if self._check_is_logged():
            self._save_cookies()
        else:
            raise LoginError('Login Request is not accepted')