Ejemplo n.º 1
0
 def get_reactions(self, access_token):
     """
     Get the posts' comments
     :return: List(Dict)
     """
     # Get the list of reactions (list of dictionaries)
     reactions = net_utils.data_request('reaction', getattr(self, 'id'),
                                        access_token)
     # Convert the list of reactions to a list of objects
     for reaction in reactions:
         try:
             self.reactions.append(Reaction(reaction))
         except:
             continue
     # Calculate each occurrences of each reaction
     summary = {
         'LIKE': 0,
         'LOVE': 0,
         'WOW': 0,
         'HAHA': 0,
         'SAD': 0,
         'ANGRY': 0,
         'THANKFUL': 0
     }
     # Looping through the reactions
     for reaction in self.reactions:
         summary[reaction.type] += 1
     # Calculate the number of all reactions
     summary['total_count'] = len(self.reactions)
     # Adding the result to the post object
     self.reactions_count = summary
Ejemplo n.º 2
0
 def get_comments(self, access_token, **kwargs):
     """
     Get the posts' comments
     :return: List(Dict)
     """
     # Get the args value from kwargs
     with_replies = kwargs.get('with_replies', False)
     # Get the list of comments (list of dictionaries)
     comments = net_utils.data_request('comment', getattr(self, 'id'),
                                       access_token)
     # Actions depending on with_replies value
     if with_replies is False:
         # Convert the list of comments to a list of objects
         for comment in comments:
             try:
                 self.comments.append(Comment(comment))
             except:
                 continue
     else:
         for comment in comments:
             _comment = Comment(comment)
             _comment.get_replies(access_token)
             self.comments.append(_comment)
     # Calculate the number of comments
     self.comments_count = len(comments)
Ejemplo n.º 3
0
 def get_posts(self, access_token, **kwargs):
     """
     Get the page posts
     :param access_token: The access token used to connect with to the server
     :param with_comments: Get the posts and their comments
     :param with_replies: Get the comments and their replies
     :param with_reactions: Get the post's reactions
     :param since: The date from where to begin the crawl
     :param until: The date of the latest post
     :param number: The number of latest posts
     :return:
     """
     # Get the value from the kwargs dict
     with_comments = kwargs.get('with_comments', False)
     with_replies = kwargs.get('with_replies', False)
     with_reactions = kwargs.get('with_reactions', False)
     since = kwargs.get('since', None)
     until = kwargs.get('until', None)
     number = kwargs.get('number', None)
     # Get the posts depending on the args
     posts = net_utils.data_request('post',
                                    getattr(self, 'id'),
                                    access_token,
                                    since=since,
                                    until=until,
                                    number=number)
     for post in posts:
         try:
             self.posts.append(Post(post))
         except:
             continue
     # Actions depending on the values of with_ args
     if with_comments is True:
         if with_reactions is True:
             # For each post
             for post in self.posts:
                 # Collect the comments of the post (replies depends on the arg)
                 post.get_comments(access_token, with_replies=with_replies)
                 # Create a new thread to collect the reactions
                 thread = threading.Thread(target=post.get_reactions,
                                           args=(access_token, ))
                 thread.start()
                 thread.join()
         else:
             # For each post
             for post in self.posts:
                 # Collect the comments of the post (replies depends on the arg)
                 post.get_comments(access_token, with_replies=with_replies)
     elif with_reactions is True:
         # For each post
         for post in self.posts:
             # Collect the comments of the post (replies depends on the arg)
             post.get_reactions(access_token)
     else:
         # If with_reactions and with_comments are both False
         pass
Ejemplo n.º 4
0
 def get_page_info(self, identifier, access_token):
     """
     Get the page information
     :param identifier: The actual page id
     :param access_token: The access token used to connect with to the server
     :return:
     """
     # Collect info about the page
     page_info = net_utils.data_request('page', identifier, access_token)
     # Copy the content in the attributes
     self.__init__(page_info)
Ejemplo n.º 5
0
 def get_replies(self, access_token):
     """
     Get the replies of the comment
     :param access_token: The access token used to autheticate with to the server
     :return:
     """
     # Get the list of replies (list of dictionaries)
     replies = net_utils.data_request('comment', self.id, access_token)
     # Convert the list of replies to a list of objects (Replies are considered as comments)
     for reply in replies:
         try:
             self.replies.append(Reply(reply))
         except:
             continue