How to use the gkeepapi.node.BlobType 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 / node.py View on Github external
def save(self, clean=True):
        ret = super(NodeDrawingInfo, self).save(clean)
        ret['drawingId'] = self.drawing_id
        ret['snapshotData'] = self.snapshot.save(clean)
        ret['snapshotFingerprint'] = self._snapshot_fingerprint
        ret['thumbnailGeneratedTime'] = NodeTimestamps.dt_to_str(self._thumbnail_generated_time)
        ret['inkHash'] = self._ink_hash
        ret['snapshotProtoFprint'] = self._snapshot_proto_fprint
        return ret

class Blob(Node):
    """Represents a Google Keep blob."""
    _blob_type_map = {
        BlobType.Audio: NodeAudio,
        BlobType.Image: NodeImage,
        BlobType.Drawing: NodeDrawing,
    }

    def __init__(self, parent_id=None, **kwargs):
        super(Blob, self).__init__(type_=NodeType.Blob, parent_id=parent_id, **kwargs)
        self.blob = None

    @classmethod
    def from_json(cls, raw):
        """Helper to construct a blob from a dict.

        Args:
            raw (dict): Raw blob representation.

        Returns:
            NodeBlob: A NodeBlob object or None.
github kiwiz / gkeepapi / gkeepapi / __init__.py View on Github external
def get(self, blob):
        """Get the canonical link to a media blob.

        Args:
            blob (gkeepapi.node.Blob): The blob.

        Returns:
            str: A link to the media.
        """
        url = self._base_url + blob.parent.server_id + '/' + blob.server_id
        if blob.blob.type == _node.BlobType.Drawing:
            url += '/' + blob.blob._drawing_info.drawing_id
        return self._send(
            url=url,
            method='GET',
            allow_redirects=False
        ).headers['location']
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
self._mimetype = raw.get('mimetype')

    def save(self, clean=True):
        ret = super(NodeBlob, self).save(clean)
        ret['kind'] = 'notes#blob'
        ret['type'] = self.type.value
        if self.blob_id is not None:
            ret['blob_id'] = self.blob_id
        if self._media_id is not None:
            ret['media_id'] = self._media_id
        ret['mimetype'] = self._mimetype
        return ret

class NodeAudio(NodeBlob):
    """Represents an audio blob."""
    _TYPE = BlobType.Audio
    def __init__(self):
        super(NodeAudio, self).__init__(type_=self._TYPE)
        self._length = None

    def _load(self, raw):
        super(NodeAudio, self)._load(raw)
        self._length = raw.get('length')

    def save(self, clean=True):
        ret = super(NodeAudio, self).save(clean)
        if self._length is not None:
            ret['length'] = self._length
        return ret

class NodeImage(NodeBlob):
    """Represents an image blob."""
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
def _load(self, raw):
        super(NodeBlob, self)._load(raw)
        # Verify this is a valid type
        BlobType(raw['type'])
        self.blob_id = raw.get('blob_id')
        self._media_id = raw.get('media_id')
        self._mimetype = raw.get('mimetype')
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
Args:
            raw (dict): Raw blob representation.

        Returns:
            NodeBlob: A NodeBlob object or None.
        """
        if raw is None:
            return None

        _type = raw.get('type')
        if _type is None:
            return None

        bcls = None
        try:
            bcls = cls._blob_type_map[BlobType(_type)]
        except (KeyError, ValueError) as e:
            logger.warning('Unknown blob type: %s', _type)
            if DEBUG:
                raise_from(exception.ParseException('Parse error for %s' % (_type), raw), e)
            return None
        blob = bcls()
        blob.load(raw)

        return blob
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
ret['byte_size'] = self._byte_size
        ret['extracted_text'] = self._extracted_text
        ret['extraction_status'] = self._extraction_status
        return ret

    @property
    def url(self):
        """Get a url to the image.
        Returns:
            str: Image url.
        """
        raise NotImplementedError()

class NodeDrawing(NodeBlob):
    """Represents a drawing blob."""
    _TYPE = BlobType.Drawing
    def __init__(self):
        super(NodeDrawing, self).__init__(type_=self._TYPE)
        self._extracted_text = ''
        self._extraction_status = ''
        self._drawing_info = None

    def _load(self, raw):
        super(NodeDrawing, self)._load(raw)
        self._extracted_text = raw.get('extracted_text')
        self._extraction_status = raw.get('extraction_status')
        drawing_info = None
        if 'drawingInfo' in raw:
            drawing_info = NodeDrawingInfo()
            drawing_info.load(raw['drawingInfo'])
        self._drawing_info = drawing_info