|
54 | 54 | BOARD_SECTION_RESOURCE = 'https://www.pinterest.com/resource/BoardSectionResource/create/' |
55 | 55 | GET_BOARD_SECTIONS = 'https://www.pinterest.com/resource/BoardSectionsResource/get/' |
56 | 56 | BOARD_SECTION_EDIT_RESOURCE = 'https://www.pinterest.com/resource/BoardSectionEditResource/delete/' |
| 57 | +GET_BOARD_SECTION_PINS = 'https://www.pinterest.com/resource/BoardSectionPinsResource/get/' |
57 | 58 | UPLOAD_IMAGE = 'https://www.pinterest.com/upload-image/' |
58 | 59 |
|
59 | 60 |
|
@@ -271,7 +272,7 @@ def pin(self, board_id, image_url, description='', link='', title='', section_id |
271 | 272 | def upload_pin(self, board_id, image_file, description='', link='', title='', section_id=None): |
272 | 273 | image_url = self._upload_image(image_file=image_file).json()['image_url'] |
273 | 274 | return self.pin(board_id=board_id, description=description, image_url=image_url, link=link, title=title, |
274 | | - section_id=section_id) |
| 275 | + section_id=section_id) |
275 | 276 |
|
276 | 277 | def repin(self, board_id, pin_id, section_id=None): |
277 | 278 | options = { |
@@ -614,18 +615,27 @@ def get_board_sections(self, board_id=''): |
614 | 615 |
|
615 | 616 | url = self.req_builder.buildGet(url=GET_BOARD_SECTIONS, options=options) |
616 | 617 | response = self.get(url=url).json() |
617 | | - return response['resource_response']['data']['ReactBoardFeedResource'] |
| 618 | + return response['resource_response']['data'] |
618 | 619 |
|
619 | | - def get_section_pins(self, username='', board_name='', section_name=''): |
| 620 | + def get_section_pins(self, section_id='', page_size=250): |
| 621 | + options = { |
| 622 | + "isPrefetch": False, |
| 623 | + "field_set_key": "react_grid_pin", |
| 624 | + "is_own_profile_pins": True, |
| 625 | + "page_size": page_size, |
| 626 | + "redux_normalize_feed": True, |
| 627 | + "section_id": section_id |
| 628 | + } |
620 | 629 |
|
621 | | - url = 'https://www.pinterest.com/{}/{}/{}/'.format(username, board_name, section_name) |
622 | | - data = self.get(url=url) |
| 630 | + url = self.req_builder.buildGet(url=GET_BOARD_SECTION_PINS, options=options) |
| 631 | + response = self.get(url=url).json() |
| 632 | + data = response['resource_response']['data'] |
| 633 | + pins = [] |
623 | 634 |
|
624 | | - soup = BeautifulSoup(data.text, 'html.parser') |
625 | | - script = soup.find("script", {"id": "initial-state"}) |
626 | | - data = json.loads(script.text)['resources']['data']['ReactBoardFeedResource'] |
627 | | - first_entry = next(iter(data.values())) |
628 | | - return first_entry['data']['section_pin_feed'] |
| 635 | + for d in data: |
| 636 | + if 'pinner' in d: |
| 637 | + pins.append(d) |
| 638 | + return pins |
629 | 639 |
|
630 | 640 | def delete_board_section(self, section_id=''): |
631 | 641 | options = { |
|
0 commit comments