class WallGetByIdMethod(BaseVkClient): METHOD = 'wall.getById' HTTP_METHOD = 'post' ARGUMENTS = { 'access_token': Argument(type=str, required=True), 'posts': Argument(type=str, required=True) }
class WallDeleteMethod(BaseVkClient): METHOD = 'wall.delete' HTTP_METHOD = 'post' ARGUMENTS = { 'access_token': Argument(type=str, required=True), 'owner_id': Argument(type=str, required=True), 'post_id': Argument(type=int, required=True) }
class SendMessage(BaseVkClient): METHOD = 'messages.send' HTTP_METHOD = 'post' ARGUMENTS = { 'access_token': Argument(type=str, required=True), 'user_id': Argument(type=str, required=True), 'message': Argument(type=str, required=True) }
class WallRepost(BaseVkClient): METHOD = 'wall.repost' HTTP_METHOD = 'post' ARGUMENTS = { 'access_token': Argument(type=str, required=True), 'object': Argument(type=str, required=True), 'message': Argument(type=str, required=True), 'group_id': Argument(type=str, required=True) }
class GroupsGetMethod(BaseVkClient): METHOD = 'groups.get' API_VERSION = '5.71' ARGUMENTS = { 'access_token': Argument(type=str, required=True), 'user_id': Argument(type=str, required=True), 'extended': Argument(type=int, required=True), 'filter': Argument(type=str, required=True), 'fields': Argument(type=str, required=True), }
class WallPostMethod(BaseVkClient): METHOD = 'wall.post' HTTP_METHOD = 'post' ARGUMENTS = { 'access_token': Argument(type=str, required=True), 'owner_id': Argument(type=str, required=True), 'attachments': ListOfArgument(argument_inst=Argument(type=dict, required=True)), 'message': Argument(type=str, required=True) } def get_arguments(self): arguments = super(WallPostMethod, self).get_arguments() attachments = arguments['attachments'] arguments['attachments'] = ','.join( self.create_attachment(item['owner_id'], item['type'], item['id']) for item in attachments ) return arguments def create_attachment(self, owner_id, object_type, object_id): return "{0}{1}_{2}".format(object_type, owner_id, object_id)
class VideoSaveMethod(BaseVkClient): METHOD = 'video.save' HTTP_METHOD = 'post' TOO_MUCH_REQUESTS_MSG = 'Too much requests' SERVICE_UNAVAILABLE = 'Page temporary unavailable' ARGUMENTS = { 'access_token': Argument(type=str, required=True), 'name': Argument(type=str, required=True), 'link': Argument(type=str, required=True), 'description': Argument(type=str, required=True), 'group_id': Argument(type=int, default=None) } @staticmethod @async_message_rate_limit() async def toggle_upload_link(upload_url: str): try: response = await Sender.get(upload_url, {}) except Exception as e: logger.error(e) if hasattr(e, 'doc'): msg = { 'url': upload_url, 'response': e.doc } if e.doc == VideoSaveMethod.TOO_MUCH_REQUESTS_MSG: return e.doc elif bool(BeautifulSoup(e.doc, "html.parser").find()): sentry_logger.error(msg=msg, extra={ 'html': e.doc }) return VideoSaveMethod.SERVICE_UNAVAILABLE else: sentry_logger.error(msg=msg) return False return response.get(VK_MESSAGE_KEY.RESPONSE) == 1