コード例 #1
0
    def post_in_group(self) -> None:
        """
        Makes deferred Posts in your Group of selected Posts in such a way that they are published after a
        certain period, calculated on the basis of their number
        """
        sec_in_hour = 60 * 60
        hours_for_publishing = self.end_post_hour - self.start_post_hour
        publish_timestamp = get_tomorrow_timestamp(
        ) + self.start_post_hour * sec_in_hour
        time_interval = round(hours_for_publishing * sec_in_hour /
                              (len(self.selected_posts) * 60))

        for post in self.selected_posts:
            attachments = (
                [f'photo{photo[0]}_{photo[1]}' for photo in post.photos] +
                [f'video{video[0]}_{video[1]}' for video in post.videos] +
                [f'audio{audio[0]}_{audio[1]}' for audio in post.audios] +
                [f'doc{doc[0]}_{doc[1]}' for doc in post.docs]
                # [f'poll{poll[0]}_{poll[1]}' for poll in post.polls] +
                # [f'note{note[0]}_{note[1]}' for note in post.notes] +
            )
            method_name = 'wall.post'
            parameters = {
                'owner_id': f'-{self.my_group_id}',
                'from_group': 1,
                'message': post.text,
                'attachments': ','.join(attachments),
                'publish_date': publish_timestamp
            }
            response = req().post(method_name, parameters)
            print(response)
            publish_timestamp += time_interval * 60
            sleep(0.33)
コード例 #2
0
ファイル: group.py プロジェクト: detkov/VK_Group_Bot_v.2
    def get_all_posts(self) -> List[Post]:
        """
        Gets information about the last 100 posts of a group and converts them to a list of instances of the Post class
        :return: list of suitable (not ads or reposts) group Posts
        """
        def suitable(post):
            return (post.get('views', 0) != 0
                    and post.get('copy_history', 0) == 0
                    and post['marked_as_ads'] == 0
                    and 'vk.com/' not in post['text']
                    and '[club' not in post['text'])

        method_name = 'wall.get'
        parameters = {
            'owner_id': f'-{self.id}',
            'count': '100',
            'offset': '1',
            'filter': 'owner'
        }
        response = req().get(method_name, parameters)
        try:
            posts = [
                Post(self.id, self.name, self.members_count, post['date'],
                     post['likes']['count'], post['reposts']['count'],
                     post['views']['count'], post['text'],
                     post.get('attachments', []))
                for post in response['response']['items'] if suitable(post)
            ]
        except:
            return []
        return posts
コード例 #3
0
 def get_group_names(self) -> List[str]:
     """
     Gets names of all Groups
     :return: list of names
     """
     method_name = 'groups.getById'
     parameters = {
         'group_ids': ','.join([str(id) for id in self.group_ids])
     }
     response = req().get(method_name, parameters)
     return [group_info['name'] for group_info in response['response']]
コード例 #4
0
 def get_group_ids(self) -> List[str]:
     """
     Gets the Group ids from your Groups link list
     :return: list of ids
     """
     method_name = 'groups.getById'
     parameters = {'group_id': self.my_group_id, 'fields': 'links'}
     response = req().get(method_name, parameters)
     short_names = [
         group_info['url'].split('/')[3]
         for group_info in response['response'][0]['links']
     ]
     return Group.get_ids_from_urls(short_names)
コード例 #5
0
ファイル: group.py プロジェクト: detkov/VK_Group_Bot_v.2
 def get_ids_from_urls(urls: List[str]) -> List[str]:
     """
     Gets ids of groups from it's short names
     :param urls: list of (screen_name)s from VK API aka short names
     :return: list of ids
     """
     method_name = 'groups.getById'
     for i, url in enumerate(urls):
         if len(url) > 5 and url[:6] == 'public':
             urls[i] = urls[i][6:]
     parameters = {'group_ids': ','.join(urls)}
     response = req().get(method_name, parameters)
     return [group_info['id'] for group_info in response['response']]
コード例 #6
0
 def get_members_count(self) -> List[str]:
     """
     Gets the number of subscribers of Groups by their ids
     :return: list with the number of subscribers of Groups
     """
     method_name = 'groups.getById'
     parameters = {
         'group_ids': ','.join([str(id) for id in self.group_ids]),
         'fields': 'members_count'
     }
     response = req().get(method_name, parameters)
     return [
         group_info['members_count'] for group_info in response['response']
         if group_info.get('deactivated', '') != 'banned'
     ]