예제 #1
0
 def sendCommentWithTypeownerIdpostIdtext(self, type, ownerId, postId,
                                          text):
     analytics.log('Posts_send_comment')
     response = {}
     try:
         if type == 'wall':
             response = self.wallPostService.sendComment(
                 ownerId, postId, text, 0)
         elif type == 'photo':
             response = self.detailPhotoService.sendComment(
                 ownerId, postId, text, 0)
         elif type == 'video':
             response = self.detailVideoService.sendComment(
                 ownerId, postId, text, 0)
     except Exception as e:
         print(
             'preloadCommentsWithTypeownerIdpostIdcountloaded exception: ' +
             str(e))
     commentId = 0
     if isinstance(response, int):
         response = {'comment_id': response}
     try:
         commentId = response['comment_id']
     except:
         pass
     if commentId == 0:
         dialogsManager = PyDialogsManager()
         dialogsManager.showDialogWithMessage('error_send_comment')
     else:
         try:
             response['user_info'] = users.getShortUserById(vk.userId())
         except:
             pass
     return response
예제 #2
0
    def report(self, type, ownerId, itemId):
        response = False
        results = 0
        dialogsManager = PyDialogsManager()
        try:
            api = vk.api()
            if type == 'post':
                results = api.wall.reportPost(owner_id=ownerId, post_id=itemId)
            elif type == 'user':
                items = ['p**n', 'spam', 'insult', 'advertisment']
                index, cancelled = dialogsManager.showRowsDialogWithTitles(
                    items)
                if cancelled:
                    return
                type = items[index]
                message, cancelled = dialogsManager.showTextFieldDialogWithText(
                    'enter_report_message')
                if cancelled:
                    return
                results = api.users.report(user_id=ownerId,
                                           type=type,
                                           comment=message)
            elif type == 'photo':
                results = api.photos.report(owner_id=ownerId, photo_id=itemId)
            elif type == 'video':
                message, cancelled = dialogsManager.showTextFieldDialogWithText(
                    'enter_report_message')
                if cancelled:
                    return
                results = api.video.report(owner_id=ownerId,
                                           video_id=itemId,
                                           comment=message)
            elif type == 'post_comment':
                results = api.wall.reportComment(owner_id=ownerId,
                                                 comment_id=itemId)
            elif type == 'photo_comment':
                results = api.photos.reportComment(owner_id=ownerId,
                                                   comment_id=itemId)
            elif type == 'video_comment':
                results = api.video.reportComment(owner_id=ownerId,
                                                  comment_id=itemId)
            else:
                raise ValueError('unsupported type of item for report')
            if isinstance(results, int) and results == 1:
                response = True

        except Exception as e:
            print('posts report exception: ' + str(e))

        if response == False:
            print('report send failed with results: ' + str(results))
            dialogsManager.showDialogWithMessage('error_reporting')
        else:
            dialogsManager.showDialogWithMessage('report_sended_successfully')
            print('report sended successfully for type: ' + str(type))
        pass
예제 #3
0
 def createPost(self, text):
     results = self.createPostService.createPost(self.ownerId, text)
     postId = 0
     try:
         postId = results['post_id']
     except:
         pass
     if postId == 0:
         dialogsManager = PyDialogsManager()
         dialogsManager.showDialogWithMessage('error_create_post')
     else:
         managers.shared().screensManager(
         ).dismissCreatePostViewController_(args=[True])
     return postId
예제 #4
0
    def doUnbanUser(self, userId):
        result = 0
        try:
            api = vk.api()
            result = api.account.unban(owner_id=userId)
        except Exception as e:
            print('unbanUser exception: ' + str(e))

        if not isinstance(result, int) or result != 1:
            message = 'error_unban_user' if userId > 0 else 'error_unban_group'
            dialogsManager = PyDialogsManager()
            dialogsManager.showDialogWithMessage(message)
            return False
        return True
예제 #5
0
    def hideSource(self, userId):
        results = 0
        try:
            api = vk.api()
            if userId > 0:
                results = api.newsfeed.addBan(user_ids=userId)
            elif userId < 0:
                results = api.newsfeed.addBan(group_ids=abs(userId))
            else:
                raise ValueError('userId on hideSource is 0')
        except Exception as e:
            print('hideSource exception: ' + str(e))

        if not isinstance(results, int) or results != 1:
            dialogsManager = PyDialogsManager()
            dialogsManager.showDialogWithMessage('error_ignore_item')
예제 #6
0
    def blockUser(self, userId):
        result = 0
        try:
            api = vk.api()
            result = api.account.ban(owner_id=userId)
        except VkAPIError as e:
            if 'already blacklisted' in e.message:
                result = 2
        except Exception as e:
            print('blockUser exception: ' + str(e))
        message = ""
        if isinstance(result, int) and result == 2:
            message = 'already_blacklisted'
        elif not isinstance(result, int) or result != 1:
            message = 'error_ban_user' if userId > 0 else 'error_ban_group'
        else:
            message = 'user_successfully_banned' if userId > 0 else 'group_successfully_banned'

        dialogsManager = PyDialogsManager()
        dialogsManager.showDialogWithMessage(message)
예제 #7
0
 def deleteComment(self, type, ownerId, commentId, parentItemOwnerId):
     results = 0
     try:
         api = vk.api()
         if type == 'post_comment':
             results = api.wall.deleteComment(owner_id=parentItemOwnerId,
                                              comment_id=commentId)
         elif type == 'photo_comment':
             results = api.photos.deleteComment(owner_id=parentItemOwnerId,
                                                comment_id=commentId)
         elif type == 'video_comment':
             results = api.video.deleteComment(owner_id=parentItemOwnerId,
                                               comment_id=commentId)
     except Exception as e:
         print('deleteComment exception: ' + str(e))
     if not isinstance(results, int) or results != 1:
         dialogsManager = PyDialogsManager()
         dialogsManager.showDialogWithMessage('error_delete_comment')
     else:
         self.guiDelegate.commentDeleted()
예제 #8
0
 def ignoreItem(self, aType, ownerId, itemId):
     results = 0
     if aType == 'post':
         type = 'wall'
     elif aType == 'photo':
         type = 'photo'
     elif aType == 'video':
         type = 'video'
     else:
         raise ValueError('unknown type for ignoreItem: ' + str(aType))
     try:
         api = vk.api()
         results = api.newsfeed.ignoreItem(type=type,
                                           owner_id=ownerId,
                                           item_id=itemId)
         print('ignoreItem result: ' + str(results) + '; ownerId: ' +
               str(ownerId) + '; itemId: ' + str(itemId))
     except Exception as e:
         print('ignoreItem exception: ' + str(e))
     if not isinstance(results, int) or results != 1:
         dialogsManager = PyDialogsManager()
         dialogsManager.showDialogWithMessage('error_ignore_item')