How to use the gkeepapi.exception function in gkeepapi

To help you get started, we’ve selected a few gkeepapi 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 kiwiz / gkeepapi / gkeepapi / __init__.py View on Github external
break

        # Sync notes. Fetch updates until we reach the newest version.
        while True:
            logger.debug('Starting keep sync: %s', self._keep_version)

            # Collect any changes and send them up to the server.
            labels_updated = any((i.dirty for i in self._labels.values()))
            changes = self._keep_api.changes(
                target_version=self._keep_version,
                nodes=[i.save() for i in self._findDirtyNodes()],
                labels=[i.save() for i in self._labels.values()] if labels_updated else None,
            )

            if changes.get('forceFullResync'):
                raise exception.ResyncRequiredException('Full resync required')

            if changes.get('upgradeRecommended'):
                raise exception.UpgradeRecommendedException('Upgrade recommended')

            # Hydrate labels.
            if 'userInfo' in changes:
                self._parseUserInfo(changes['userInfo'])

            # Hydrate notes and any children.
            if 'nodes' in changes:
                self._parseNodes(changes['nodes'])

            self._keep_version = changes['toVersion']
            logger.debug('Finishing sync: %s', self._keep_version)

            # Check if there are more changes to retrieve.
github kiwiz / gkeepapi / gkeepapi / __init__.py View on Github external
LoginException: If :py:meth:`login` has not been called.
        """
        # Send a request to the API servers, with retry handling. OAuth tokens
        # are valid for several hours (as of this comment).
        i = 0
        while True:
            # Send off the request. If there was no error, we're good.
            response = self._send(**req_kwargs).json()
            if 'error' not in response:
                break

            # Otherwise, check if it was a non-401 response code. These aren't
            # handled, so bail.
            error = response['error']
            if error['code'] != 401:
                raise exception.APIException(error['code'], error)

            # If we've exceeded the retry limit, also bail.
            if i >= self.RETRY_CNT:
                raise exception.APIException(error['code'], error)

            # Otherwise, try requesting a new OAuth token.
            logger.info('Refreshing access token')
            self._auth.refresh()
            i += 1

        return response
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
"""Helper to construct a node from a dict.

    Args:
        raw (dict): Raw node representation.

    Returns:
        Node: A Node object or None.
    """
    ncls = None
    _type = raw.get('type')
    try:
        ncls = _type_map[NodeType(_type)]
    except (KeyError, ValueError) as e:
        logger.warning('Unknown node type: %s', _type)
        if DEBUG:
            raise_from(exception.ParseException('Parse error for %s' % (_type), raw), e)
        return None
    node = ncls()
    node.load(raw)

    return node
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
def _load(self, raw):
        super(Node, self)._load(raw)
        # Verify this is a valid type
        NodeType(raw['type'])
        if raw['kind'] not in ['notes#node']:
            logger.warning('Unknown node kind: %s', raw['kind'])

        if 'mergeConflict' in raw:
            raise exception.MergeException(raw)

        self.id = raw['id']
        self.server_id = raw['serverId'] if 'serverId' in raw else self.server_id
        self.parent_id = raw['parentId']
        self._sort = raw['sortValue'] if 'sortValue' in raw else self.sort
        self._version = raw['baseVersion'] if 'baseVersion' in raw else self._version
        self._text = raw['text'] if 'text' in raw else self._text
        self.timestamps.load(raw['timestamps'])
        self.settings.load(raw['nodeSettings'])
        self.annotations.load(raw['annotationsGroup'])
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
def load(self, raw):
        """Unserialize from raw representation. (Wrapper)

        Args:
            raw (dict): Raw.
        Raises:
            ParseException: If there was an error parsing data.
        """
        try:
            self._load(raw)
        except (KeyError, ValueError) as e:
            raise_from(exception.ParseException('Parse error in %s' % (type(self)), raw), e)
github kunesj / conkyKeep / conkyKeep / google_keep_parsers.py View on Github external
def __init__(self, login, pwd, cache_path=None, **kwargs):
        self.keep = gkeepapi.Keep()
        self.keep.login(login, pwd)

        if cache_path is not None:
            cachefile_path = os.path.join(cache_path, self.NOTES_CACHEFILE)
            # restore dat from cache
            if os.path.exists(cachefile_path):
                with open(cachefile_path, 'r') as fh:
                    self.keep.restore(json.load(fh))
            # update data
            try:
                self.keep.sync()
            except gkeepapi.exception.ResyncRequiredException:
                self.keep = gkeepapi.Keep()
                self.keep.login(login, pwd)
                self.keep.sync()
            # save updated data to cache
            with open(cachefile_path, 'w') as fh:
                json.dump(self.keep.dump(), fh)
        else:
            self.keep.sync()
github kiwiz / gkeepapi / gkeepapi / __init__.py View on Github external
while True:
            logger.debug('Starting keep sync: %s', self._keep_version)

            # Collect any changes and send them up to the server.
            labels_updated = any((i.dirty for i in self._labels.values()))
            changes = self._keep_api.changes(
                target_version=self._keep_version,
                nodes=[i.save() for i in self._findDirtyNodes()],
                labels=[i.save() for i in self._labels.values()] if labels_updated else None,
            )

            if changes.get('forceFullResync'):
                raise exception.ResyncRequiredException('Full resync required')

            if changes.get('upgradeRecommended'):
                raise exception.UpgradeRecommendedException('Upgrade recommended')

            # Hydrate labels.
            if 'userInfo' in changes:
                self._parseUserInfo(changes['userInfo'])

            # Hydrate notes and any children.
            if 'nodes' in changes:
                self._parseNodes(changes['nodes'])

            self._keep_version = changes['toVersion']
            logger.debug('Finishing sync: %s', self._keep_version)

            # Check if there are more changes to retrieve.
            if not changes['truncated']:
                break