Ejemplo n.º 1
0
Archivo: api.py Proyecto: atbe/PinPy
    def get_visually_similar_pins(self, pin_id, bookmark=None, page_size=100):
        """
		Collect visually similar Pins of a particular Pin.
		NOTICE: This endpoint is rate limited

		:param pin_id: Pin ID to collect the similar pins of
		:param bookmark: Pinterest API bookmark used for pagination
		:param page_size: Number of items to collect for pagination
		:rtype: List of similar pins (paginated)
		"""

        if not self.v3_access_token:
            raise RuntimeError(
                'API v3 token not provided to API client! Cannot use this method (get_similar_pins).'
            )

        api_endpoint = f"{self.host}/v3/visual_search/flashlight/pin/{pin_id}/?x=0&y=0&w=1&h=1&"
        if bookmark:
            request_url = f"{api_endpoint}page_size={page_size}&bookmark={bookmark}&access_token={self.v3_access_token}"
            return self.call(request_url)
        else:
            request_url = "{}page_size={}&access_token={}".format(
                api_endpoint, page_size, self.v3_access_token)
            return pinpy.BookmarkPagination(self.call(request_url), pin_id,
                                            self.get_visually_similar_pins)
Ejemplo n.º 2
0
Archivo: api.py Proyecto: atbe/PinPy
    def get_public_board_pins(self, board_id, cursor=None):
        """
		Gets all pins on a board (paginated)

		:param board_id: ID of board to collect
		:param cursor: Cursor used for pagination
		:rtype: List of pins (paginated)
		"""

        desired_attributes = [
            'attribution', 'board', 'color', 'counts', 'created_at', 'creator',
            'id', 'image', 'link', 'media', 'metadata', 'note',
            'original_link', 'url'
        ]
        desired_attributes = [atr + '%2C' for atr in desired_attributes]
        api_endpoint = self.host + self.api_root + "/boards/{:s}/pins".format(
            str(board_id))
        if cursor:
            request_url = "{}?cursor={}&access_token={}".format(
                api_endpoint, cursor, self.access_token)
        else:
            request_url = "{}?access_token={}".format(api_endpoint,
                                                      self.access_token)
        request_url += "&fields={}".format(''.join(desired_attributes))
        request_url = request_url.rstrip('%2C')
        if cursor:
            return self.call(request_url)
        else:
            return pinpy.BookmarkPagination(self.call(request_url), board_id,
                                            self.get_public_board_pins)
Ejemplo n.º 3
0
	def get_user_boards(self, user_id, bookmark=None, page_size=100):
		"""
		Collect a users boards

		:param user_id: ID of user whose boards will be collected
		:param bookmark: Pinterest API bookmark used for pagination
		:param page_size: Number of items to collect for pagination
		:rtype: List of users boards (paginated)
		"""

		if not self.v3_access_token:
			raise RuntimeError('API v3 token not provided to API client! Cannot use this method (get_users_boards).')

		api_endpoint = f"{self.host}/v3/users/{user_id}/boards"
		if bookmark:
			request_url = f"{api_endpoint}/?page_size={page_size}&bookmark={bookmark}&access_token={self.v3_access_token}"
			return self.call(request_url)
		else:
			request_url = "{}/?page_size={}&access_token={}".format(api_endpoint, page_size, self.v3_access_token)
			return pinpy.BookmarkPagination(self.call(request_url), user_id, self.get_user_boards)
Ejemplo n.º 4
0
	def get_pin_comments_v3(self, pin_id, bookmark=None, page_size=100):
		"""
		Collect the comments made on a Pin

		:param pin_id: Pin ID to collect the comments from
		:param bookmark: Pinterest API bookmark used for pagination
		:param page_size: Number of items to collect for pagination
		:rtype: List of comments (paginated)
		"""

		if not self.v3_access_token:
			raise RuntimeError('API v3 token not provided to API client! Cannot use this method (get_pin_comments_v3).')

		api_endpoint = f"{self.host}/v3/pins/{pin_id}/comments/"
		if bookmark:
			request_url = f"{api_endpoint}?page_size={page_size}&bookmark={bookmark}&access_token={self.v3_access_token}"
			return self.call(request_url)
		else:
			request_url = f"{api_endpoint}?page_size={page_size}&access_token={self.v3_access_token}"
			return pinpy.BookmarkPagination(self.call(request_url), pin_id, self.get_pin_comments_v3)
Ejemplo n.º 5
0
	def get_user_following_v3(self, user_id, bookmark=None, page_size=100):
		"""
		Collect the users someone follows

		:param user_id: User ID of user whose followees will be collected
		:param bookmark: Pinterest API bookmark used for pagination
		:param page_size: Number of items to collect for pagination
		:rtype: List of user profiles (the followees)
		"""

		if not self.v3_access_token:
			raise RuntimeError('API v3 token not provided to API client! Cannot use this method (get_user_following_v3).')

		api_endpoint = f"{self.host}/v3/users/{user_id}/following/"
		if bookmark:
			request_url = f"{api_endpoint}?page_size={page_size}&bookmark={bookmark}&access_token={self.v3_access_token}"
			return self.call(request_url)
		else:
			request_url = f"{api_endpoint}?page_size={page_size}&access_token={self.v3_access_token}"
			return pinpy.BookmarkPagination(self.call(request_url), user_id, self.get_user_following_v3)
Ejemplo n.º 6
0
	def get_public_board_pins_v3(self, board_id, bookmark=None, page_size=100):
		"""
		Collects the pins in a board

		:param board_id: ID of board whos pins will be collected
		:param bookmark: Pinterest API bookmark used for pagination
		:param page_size: Number of items to collect for pagination
		:rtype: List of pins found in the board (paginated)
		"""

		if not self.v3_access_token:
			raise RuntimeError('API v3 token not provided to API client! Can\'t this method (get_public_board_pins_v3).')

		api_endpoint = f"{self.host}/v3/boards/{board_id}/pins/"
		if bookmark:
			request_url = f"{api_endpoint}?page_size={page_size}&bookmark={bookmark}&access_token={self.v3_access_token}"
			return self.call(request_url)
		else:
			request_url = f"{api_endpoint}?page_size={page_size}&access_token={self.v3_access_token}"
			return pinpy.BookmarkPagination(self.call(request_url), board_id, self.get_public_board_pins_v3)