How to use the gkeepapi.node.NodeType 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 / test / test_nodes.py View on Github external
        a, b = generate_save_load(lambda: node.Node(type_=node.NodeType.Note))
        self.assertEqual(a, b)
github PiotrMachowski / Home-Assistant-custom-components-Google-Keep / custom_components / google_keep / sensor.py View on Github external
notes = self._keep.all()
        if len(self._labels) > 0:
            notes = list(
                filter(lambda n: set(self._labels).intersection(set(map(lambda l: str(l), n.labels.all()))), notes))
        if len(self._titles) > 0:
            notes = list(filter(lambda n: str(n.title) in self._titles, notes))
        self._notes = []
        for note in notes:
            note_type = note.type
            title = str(note.title)
            lines = list(map(lambda n: str(n), note.text.split("\n")))
            color = note.color.name
            checked = []
            unchecked = []
            children = []
            if note_type == NodeType.List:
                checked = list(map(lambda n: str(n), note.checked))
                unchecked = list(map(lambda n: str(n), note.unchecked))
                children = list(
                    map(lambda c: GoogleKeepSensor.map_node(c), filter(lambda c: not c.indented, note.items)))
            parsed_note = GoogleKeepSensor.make_note(str(note_type), title, lines, children, checked, unchecked, color)
            self._notes.append(parsed_note)
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
    @merged.setter
    def merged(self, value):
        self._merged = value
        self.touch()

    @property
    def dirty(self):
        return super(Label, self).dirty or self.timestamps.dirty

    def __str__(self):
        return self.name

_type_map = {
    NodeType.Note: Note,
    NodeType.List: List,
    NodeType.ListItem: ListItem,
    NodeType.Blob: Blob,
}

def from_json(raw):
    """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:
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
    @property
    def dirty(self):
        return super(TopLevelNode, self).dirty or self.labels.dirty or self.collaborators.dirty

    @property
    def blobs(self):
        """Get all media blobs.

        Returns:
            list[gkeepapi.node.Blob]: Media blobs.
        """
        return [node for node in self.children if isinstance(node, Blob)]

class Note(TopLevelNode):
    """Represents a Google Keep note."""
    _TYPE = NodeType.Note
    def __init__(self, **kwargs):
        super(Note, self).__init__(type_=self._TYPE, **kwargs)

    def _get_text_node(self):
        node = None
        for child_node in self.children:
            if isinstance(child_node, ListItem):
                node = child_node
                break

        return node

    @property
    def text(self):
        node = self._get_text_node()
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
def __init__(self, parent_id=None, parent_server_id=None, super_list_item_id=None, **kwargs):
        super(ListItem, self).__init__(type_=NodeType.ListItem, parent_id=parent_id, **kwargs)
        self.parent_item = None
        self.parent_server_id = parent_server_id
        self.super_list_item_id = super_list_item_id
        self.prev_super_list_item_id = None
        self._subitems = {}
        self._checked = False
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
def merged(self, value):
        self._merged = value
        self.touch()

    @property
    def dirty(self):
        return super(Label, self).dirty or self.timestamps.dirty

    def __str__(self):
        return self.name

_type_map = {
    NodeType.Note: Note,
    NodeType.List: List,
    NodeType.ListItem: ListItem,
    NodeType.Blob: Blob,
}

def from_json(raw):
    """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:
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
def from_json(raw):
    """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