Skip to content

Commit

Permalink
Pinterest.py type_ahead method added (#102)
Browse files Browse the repository at this point in the history
/resource/AdvancedTypeaheadResource/get

to get pinterest predictions for given term. useful for sub-topic exploration and finding users that related with given term.
  • Loading branch information
kruvatz authored Dec 16, 2020
1 parent 9603541 commit 82f1e82
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions py3pin/Pinterest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
BOARD_DELETE_INVITE_RESOURCE = 'https://www.pinterest.com/_ngjs/resource/BoardCollaboratorResource/delete/'
VISUAL_LIVE_SEARCH_RESOURCE = 'https://www.pinterest.com/resource/VisualLiveSearchResource/get'
SEARCH_RESOURCE = 'https://www.pinterest.com/resource/SearchResource/get'
TYPE_AHEAD_RESOURCE = "https://www.pinterest.com/resource/AdvancedTypeaheadResource/get"
BOARD_RECOMMEND_RESOURCE = 'https://www.pinterest.com/_ngjs/resource/BoardContentRecommendationResource/get'
PINNABLE_IMAGES_RESOURCE = 'https://www.pinterest.com/_ngjs/resource/FindPinImagesResource/get'
BOARD_FEED_RESOURCE = 'https://www.pinterest.com/resource/BoardFeedResource/get'
Expand Down Expand Up @@ -1027,3 +1028,21 @@ def delete_board_section(self, section_id=''):
}
data = self.req_builder.buildPost(options=options)
return self.post(url=BOARD_SECTION_EDIT_RESOURCE, data=data)

def type_ahead(self,scope="pins",count=5,term=""):
"""
returns Pinterest predictions for given term.
Response may include user profiles.
Example term "dada" gives ["dadaism","dada art"] etc.
:param scope: always "pins"
:param count: max guess number
:param term: word to be typed ahead
:return: response items
"""

source_url= "/"
options = {"pin_scope":scope,"count":count,"term":term,"no_fetch_context_on_resource":False}
url = self.req_builder.buildGet(TYPE_AHEAD_RESOURCE,options,source_url)

resp = self.get(url=url).json()
return resp["resource_response"]["data"]["items"]

0 comments on commit 82f1e82

Please sign in to comment.