From 8932e62608f8a88e87a46984dc3ad6e5275a4b49 Mon Sep 17 00:00:00 2001 From: "b.stoilov" Date: Tue, 3 May 2022 19:23:14 +0300 Subject: [PATCH] Bug fixes and add pin note --- examples.py | 10 +++++++--- py3pin/Pinterest.py | 21 +++++++++++++++++++-- py3pin/__version__.py | 2 +- requirements.txt | 1 - setup.py | 2 +- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/examples.py b/examples.py index 1afeb2e..fb4d121 100644 --- a/examples.py +++ b/examples.py @@ -14,7 +14,7 @@ # login will obtain and store cookies for further use, they last around 15 days. # NOTE: Since login will store the cookies in local file you don't need to call it more then 3-4 times a month. -# pinterest.login() +# pinterest.login(headless=True) def get_user_profile(): return pinterest.get_user_overview(username='username') @@ -127,9 +127,10 @@ def pin(board_id='', image_url='https://i.pinimg.com/170x/32/78/bd/3278bd27073e1ec9c8a708409279768b.jpg', description='this is auto pin', title='a bot did this', + alt_text='alt text', link='https://www.google.com/'): - return pinterest.pin(board_id=board_id, section_id=section_id, image_url=image_url, description=description, - title=title, link=link) + return pinterest.pin(board_id=board_id, section_id=section_id, image_url=image_url, + alt_text=alt_text, description=description, title=title, link=link) def upload_pin(board_id='', @@ -228,3 +229,6 @@ def get_board_section_feed(section_id=''): def type_ahead(term="apple"): return pinterest.type_ahead(term=term) + +def add_pin_note(pin_id, note='test note'): + pinterest.add_pin_note(pin_id=pin_id, note=note) diff --git a/py3pin/Pinterest.py b/py3pin/Pinterest.py index 0f920f4..2c3ab28 100644 --- a/py3pin/Pinterest.py +++ b/py3pin/Pinterest.py @@ -109,6 +109,7 @@ ) UPLOAD_IMAGE = "https://www.pinterest.com/upload-image/" BOARD_FOLLOWERS = "https://pinterest.com/resource/BoardFollowersResource/get/" +ADD_PIN_NOTE = "https://www.pinterest.com/resource/ApiResource/create/" class Pinterest: @@ -562,7 +563,7 @@ def get_user_followers_all(self, username=None): return followers def pin( - self, board_id, image_url, description="", link="", title="", section_id=None + self, board_id, image_url, description="", link="", title="", alt_text="", section_id=None ): """ Perfoms a pin operation. If you want to upload local image use 'upload_pin' @@ -580,8 +581,9 @@ def pin( "description": description, "link": link if link else image_url, "scrape_metric": {"source": "www_url_scrape"}, - "method": "scraped", + "method": "uploaded", "title": title, + "alt_text": alt_text, "section": section_id, } source_url = "/pin/find/?url={}".format(self.req_builder.url_encode(image_url)) @@ -1252,3 +1254,18 @@ def type_ahead(self, scope="pins", count=5, term=""): resp = self.get(url=url).json() return resp["resource_response"]["data"]["items"] + + def add_pin_note(self, pin_id, note): + """ + Adds a note to pin + """ + options = { + "url": "/v3/pins/{}/notes/".format(pin_id), + "data": { + "pin_note_content": note + } + } + + data = self.req_builder.buildPost(options=options, source_url="/pin/{}/".format(pin_id)) + return self.post(url=ADD_PIN_NOTE, data=data) + diff --git a/py3pin/__version__.py b/py3pin/__version__.py index 923b987..19b4f1d 100644 --- a/py3pin/__version__.py +++ b/py3pin/__version__.py @@ -1 +1 @@ -__version__ = '1.2.2' +__version__ = '1.3.0' diff --git a/requirements.txt b/requirements.txt index bec95e3..1853f72 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -PyQt5 beautifulsoup4 requests-toolbelt selenium diff --git a/setup.py b/setup.py index 2892295..f0e0aae 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ EMAIL = 'boriostoilov@gmail.com' AUTHOR = 'Borislav Stoilov' REQUIRES_PYTHON = '>=3.5.0' -REQUIRED = ['requests', 'beautifulsoup4', 'requests-toolbelt', 'PyQt5', 'selenium', 'webdriver-manager'] +REQUIRED = ['requests', 'beautifulsoup4', 'requests-toolbelt', 'selenium', 'webdriver-manager'] here = os.path.abspath(os.path.dirname(__file__))