Beispiel #1
0
    def get_recent_posts(self, amt: int = 71) -> List[Post]:
        """
        Return a list of recent posts to the hasthag

        Parameters
        ----------
        amt : int
            Amount of recent posts to return

        Returns
        -------
        posts : List[Post]
            List containing the recent 12 posts and their available data
        """
        posts = []
        post_arr = self.json_dict["entry_data"]["TagPage"][0]["graphql"][
            "hashtag"]["edge_hashtag_to_media"]["edges"]
        amount_of_posts = len(post_arr)
        if amt > amount_of_posts:
            amt = amount_of_posts
        for post in post_arr[:amt]:
            json_dict = post["node"]
            mapping = _PostMapping.post_from_hashtag_mapping()
            post = Post(json_dict)
            post.scrape(mapping=mapping)
            posts.append(post)
        return posts
Beispiel #2
0
    def get_recent_posts(self, amt: int = 12) -> List[Post]:
        """
        Return a list of the profiles recent posts

        Parameters
        ----------
        amt : int
            Amount of recent posts to return

        Returns
        -------
        posts : List[Post]
            List containing the recent 12 posts and their available data
        """
        if amt > 12:
            raise IndexError(
                f"{amt} is too large, 12 is max available posts. Getting more posts will require an out-of-the-box extension."
            )
        posts = []
        try:
            post_arr = self.json_dict["entry_data"]["ProfilePage"][0][
                "graphql"]["user"]["edge_owner_to_timeline_media"]["edges"]
        except TypeError:
            raise ValueError(
                "Can't return posts without first scraping the Profile. Call the scrape method on your object first."
            )

        for post in post_arr[:amt]:
            json_dict = post["node"]
            mapping = _PostMapping.post_from_profile_mapping()
            post = Post(json_dict)
            post.scrape(mapping=mapping)
            posts.append(post)
        return posts
Beispiel #3
0
    def get_recent_posts(self, amt: int = 12) -> List[Post]:
        """
        Return a list of the profiles recent posts

        Parameters
        ----------
        amt : int
            Amount of recent posts to return

        Returns
        -------
        posts : List[Post]
            List containing the recent 12 posts and their available data
        """
        if amt > 12:
            raise IndexError(f"{amt} is too large, 12 is max available posts")
        posts = []
        post_arr = self.json_dict["entry_data"]["ProfilePage"][0]["graphql"][
            "user"]["edge_owner_to_timeline_media"]["edges"]
        for post in post_arr[:amt]:
            json_dict = post["node"]
            mapping = _PostMapping.post_from_profile_mapping()
            post = Post(json_dict)
            post.load(mapping=mapping)
            posts.append(post)
        return posts
Beispiel #4
0
 def _create_post_objects(self, post_soup):
     """Create a Post object from the given shortcode"""
     posts = []
     for post in post_soup:
         shortcode = post["href"].replace("/p/", "")[:-1]
         posts.append(Post(shortcode))
     return posts
Beispiel #5
0
    def get_recent_posts(self, headers, amt: int = 12) -> List[Post]:
        """
        Return a list of the profiles recent posts. Max available for return
        is 12.

        Parameters
        ----------
        amt : int
            Amount of recent posts to return

        Returns
        -------
        posts : List[Post]
            List containing the recent 12 posts and their available data
        """
        if amt > 12:
            raise IndexError(
                f"{amt} is too large, 12 is max available posts. Getting more posts will require an out-of-the-box extension."
            )
        posts = []
        try:
            post_arr = self.json_dict["entry_data"]["ProfilePage"][0]["graphql"]["user"][
                "edge_owner_to_timeline_media"
            ]["edges"]
        except TypeError:
            raise ValueError(
                "Can't return posts without first scraping the Profile. Call the scrape method on your object first."
            )

        for post in post_arr[:amt]:
            json_dict = post["node"]
            # print("KAKOY2")
            # print(json_dict)
            # print(json_dict["edge_media_to_caption"])
            # print(json_dict["edge_media_to_caption"]["edges"])
            # print(json_dict["edge_media_to_caption"]["edges"][0])
            # print(json_dict["edge_media_to_caption"]["edges"][0]["node"])
            # print(json_dict["edge_media_to_caption"]["edges"][0]["node"]["text"])
            caption_text = ""
            try:
                caption_text = str(json_dict["edge_media_to_caption"]["edges"][0]["node"]["text"]).encode('utf-8', 'replace').decode()
            except Exception as e:
                caption_text = "not found post caption text"
            # print(c_v)
            mapping = _PostMapping.post_from_profile_mapping()
            post = Post(json_dict)
            post.scrape(mapping=mapping, headers=headers)
            post.username = self.username
            post.full_name = str(self.full_name).encode('utf-8', 'replace').decode()
            post.caption = caption_text
            posts.append(post)
        return posts