How to use the gkeepapi.node.ListItem 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
def test_fields(self):
        n = node.ListItem()

        TEXT = 'Text'
        CHECKED = False

        clean_node(n)
        n.text = TEXT
        self.assertTrue(n.dirty)
        self.assertEqual(TEXT, n.text)

        clean_node(n)
        n.checked = CHECKED
        self.assertTrue(n.dirty)
        self.assertEqual(CHECKED, n.checked)
github kiwiz / gkeepapi / test / test_nodes.py View on Github external
def test_save_load(self):
        a, b = generate_save_load(lambda: node.Node(type_=node.NodeType.Note))
        self.assertEqual(a, b)

        a, b = generate_save_load(lambda: node.TopLevelNode(type_=node.NodeType.Note))
        self.assertEqual(a, b)

        a, b = generate_save_load(node.Note)
        self.assertEqual(a, b)

        a, b = generate_save_load(node.List)
        self.assertEqual(a, b)

        a, b = generate_save_load(node.ListItem)
        self.assertEqual(a, b)
github kiwiz / gkeepapi / test / test_nodes.py View on Github external
clean_node(n)
        n.text = TEXT
        self.assertTrue(n.dirty)
        self.assertEqual(TEXT, n.text)

        clean_node(n)
        n.settings.new_listitem_placement = ITEMPLACEMENT
        self.assertTrue(n.dirty)
        self.assertEqual(ITEMPLACEMENT, n.settings.new_listitem_placement)

        clean_node(n)
        n.annotations.category = None
        self.assertTrue(n.dirty)
        self.assertEqual(None, n.annotations.category)

        sub = node.ListItem()
        clean_node(sub)

        clean_node(n)
        n.append(sub)
        self.assertTrue(n.dirty)

        clean_node(n)
        sub.text = TEXT
        self.assertTrue(n.dirty)

        clean_node(n)
        sub.delete()
        self.assertTrue(n.dirty)
github kiwiz / keep-cli / keep_cli / widget / edit.py View on Github external
def _save(self):
        title = self.w_title.get_edit_text()
        if self.note.title != title:
            self.note.title = title

        if not isinstance(self.note, gkeepapi.node.List):
            text = self.w_text.get_edit_text()
            if self.note.text != text:
                self.note.text = text
            return

        old_items = set((item.id for item in self.note.items))

        for i, w_item in enumerate(self.w_list.body):
            item = gkeepapi.node.ListItem(id_=w_item.id, parent_id=self.note.id)
            if w_item.id in old_items:
                item = self.note.get(w_item.id)
                old_items.remove(w_item.id)

            if item.checked != w_item.checked:
                item.checked = w_item.checked
            text = w_item.getText()
            if item.text != text:
                item.text = text

            if item.new:
                self.note.append(item)

            curr = None
            prev = item.super_list_item_id
            if i > 0 and w_item.indented:
github kiwiz / keep-cli / keep_cli / widget / edit.py View on Github external
return actual_key(self._keypress_up(size))
        elif self._command_map[key] == NEXT_SELECTABLE:
            return actual_key(self._keypress_down(size))

        key = super(Items, self).keypress(size, key)
        if key == 'enter':
            pos = 0
            text = ''
            indented = None
            if self.focus is not None:
                text = self.focus.cutToEnd()
                pos = self.focus_position + 1

            if pos > 0:
                indented = self.body[pos - 1].indented
            item = gkeepapi.node.ListItem()
            item.text = text
            self.body.insert(pos, Item(item, indented))
            self.focus.setPos(0)
            self.focus_position = pos
            key = None
        elif key == 'backspace':
            pos = self.focus_position
            if pos > 0:
                text = self.body[pos].getText()
                last = pos == len(self.body) - 1
                del self.body[pos]
                if not last:
                    self.focus_position -= 1
                self.focus.appendText(text)
        elif key == 'meta [':
            pos = self.focus_position
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:
        ncls = _type_map[NodeType(_type)]
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
def add(self, text, checked=False, sort=None):
        """Add a new item to the list.

        Args:
            text (str): The text.
            checked (bool): Whether this item is checked.
            sort (Union[gkeepapi.node.NewListItemPlacementValue, int]): Item id for sorting or a placement policy.
        """
        node = ListItem(parent_id=self.id, parent_server_id=self.server_id)
        node.checked = checked
        node.text = text

        items = list(self.items)
        if isinstance(sort, int):
            node.sort = sort
        elif isinstance(sort, NewListItemPlacementValue) and len(items):
            func = max
            delta = self.SORT_DELTA
            if sort == NewListItemPlacementValue.Bottom:
                func = min
                delta *= -1

            node.sort = func((int(item.sort) for item in items)) + delta

        self.append(node, True)
github kiwiz / gkeepapi / gkeepapi / node.py View on Github external
def text(self, value):
        node = self._get_text_node()
        if node is None:
            node = ListItem(parent_id=self.id)
            self.append(node, True)
        node.text = value
        self.touch(True)