diff --git a/py3pin/BookmarkManager.py b/py3pin/BookmarkManager.py index f94bb1a..d88dc4b 100644 --- a/py3pin/BookmarkManager.py +++ b/py3pin/BookmarkManager.py @@ -20,3 +20,9 @@ def get_bookmark(self, primary, secondary=None): pass return None + + def reset_bookmark(self, primary, secondary=None): + if primary in self.bookmark_map: + del self.bookmark_map[primary][secondary] + else: + pass diff --git a/py3pin/Pinterest.py b/py3pin/Pinterest.py index e564ea3..e45d304 100644 --- a/py3pin/Pinterest.py +++ b/py3pin/Pinterest.py @@ -860,7 +860,6 @@ def _get_conversation_batch(self): url = self.req_builder.buildGet(url=CONVERSATION_RESOURCE, options=options) response = self.get(url=url).json() - next_bookmark = response['resource']['options']['bookmarks'][0] self.bookmark_manager.add_bookmark(primary='conversations', bookmark=next_bookmark) @@ -880,21 +879,33 @@ def create_board_section(self, board_id='', section_name=''): data = self.req_builder.buildPost(options=options) return self.post(url=BOARD_SECTION_RESOURCE, data=data) - def get_board_sections(self, board_id=''): + + def get_board_sections(self, board_id='', reset_bookmark=False): """ Obtains a list of all sections of a board """ + next_bookmark = self.bookmark_manager.get_bookmark(primary='board_sections', secondary=board_id) + if next_bookmark == '-end-': + if reset_bookmark: + self.bookmark_manager.reset_bookmark(primary='board_sections', secondary=board_id) + return [] + options = { "isPrefetch": False, "board_id": board_id, - "redux_normalize_feed": True + "redux_normalize_feed": True, + "bookmarks": [next_bookmark] } url = self.req_builder.buildGet(url=GET_BOARD_SECTIONS, options=options) response = self.get(url=url).json() + bookmark = response['resource']['options']['bookmarks'][0] + self.bookmark_manager.add_bookmark(primary='board_sections', secondary=board_id, bookmark=bookmark) + return response['resource_response']['data'] - def get_section_pins(self, section_id='', page_size=250): + + def get_section_pins(self, section_id='', page_size=250, reset_bookmark=False): """ Returns a list of all pins in a board section. This method is batched meaning in order to obtain all pins in the section @@ -902,6 +913,8 @@ def get_section_pins(self, section_id='', page_size=250): """ next_bookmark = self.bookmark_manager.get_bookmark(primary='section_pins', secondary=section_id) if next_bookmark == '-end-': + if reset_bookmark: + self.bookmark_manager.reset_bookmark(primary='section_pins', secondary=section_id) return [] options = { @@ -927,6 +940,7 @@ def get_section_pins(self, section_id='', page_size=250): pins.append(d) return pins + def delete_board_section(self, section_id=''): """ Deletes a board section by id