예제 #1
0
 def getFriends(self, userId, offset):
     usersData = []
     try:
         ids = self.getFriendsIds(userId, offset, UsersListTypes.FRIENDS)
         usersData = users.getShortUsersByIds(ids)
     except ConnectionError as e:
         raise e
     #print('getFriends usersData: ' + json.dumps(usersData, indent=4))
     return {'response': usersData}
예제 #2
0
 def getFollowers(self, userId, offset):
     usersData = []
     try:
         ids = self.getFriendsIds(userId, offset, UsersListTypes.FOLLOWERS)
         usersData = users.getShortUsersByIds(set(ids))
     except ConnectionError as e:
         raise e
     #print('FOLLOWERS response: ' + str(usersData))
     return {'response': usersData}
예제 #3
0
 def getSubscriptions(self, userId, offset):
     usersData = []
     try:
         ids = self.getFriendsIds(userId, offset,
                                  UsersListTypes.SUBSCRIPTIONS)
         usersData = users.getShortUsersByIds(set(ids))
     except ConnectionError as e:
         raise e
     #print('getSubscriptions response: ' + str(usersData))
     return {'response': usersData}
예제 #4
0
 def usersDataFromAnswers(self, l):
     userIds = []
     for d in l:
         type = d.get('type')
         if type in ['like_post', 'like_photo', 'like_comment']:
             userIds.extend([d.get('from_id') for d in d.get('feedback').get('items') if d.get('from_id')])
         elif type == 'reply_comment' or type == 'comment_post':
             fromId = d.get('feedback').get('from_id')
             if fromId:
                 userIds.append(fromId)
    
     ids = set(userIds)
     usersData = users.getShortUsersByIds(ids)
     return usersData
예제 #5
0
 def usersDataFromPosts(self, l):
     fromIds = []
     ownerIds = []
     sourceIds = []
     friends = []
     try:
         fromIds = [d['from_id'] for d in l]
     except:
         pass
     try:
         ownerIds = [d['owner_id'] for d in l]
     except:
         pass
     try:
         sourceIds = [d['source_id'] for d in l]
     except:
         pass
     
     for d in l:
         if d.get('type') == 'friend':
             friends.extend([id.get('user_id') for id in d.get('friends').get('items') if isinstance(id.get('user_id'), int)])
     
     def getId(object, key):
         if isinstance(object, list):
             return [d.get(key) for d in object]
         return None
     
     historyFromIds = [getId(d.get('copy_history'), 'owner_id') for d in l if getId(d.get('copy_history'), 'owner_id')]
     historyOwnerIds = [getId(d.get('copy_history'), 'from_id') for d in l if getId(d.get('copy_history'), 'from_id')]
     historySourceIds = [getId(d.get('copy_history'), 'source_id') for d in l if getId(d.get('copy_history'), 'source_id')]
     
     historyFromIds = [item for sublist in historyFromIds for item in sublist]
     historyOwnerIds = [item for sublist in historyOwnerIds for item in sublist]
     historySourceIds = [item for sublist in historySourceIds for item in sublist]
     
     ids = set()
     ids |= set(fromIds)
     ids |= set(ownerIds)
     ids |= set(sourceIds)
     ids |= set(historyFromIds)
     ids |= set(historyOwnerIds)
     ids |= set(friends)
     
     ids.discard(None)
     #ids |= set(historySourceIds)
     
     usersData = users.getShortUsersByIds(ids)
     #print('historySourceIds: ' + str(historySourceIds))
     return usersData
예제 #6
0
 def getBanned(self, offset):
     response = None
     count = 0
     try:
         api = vk.api()
         response = api.account.getBanned(offset=offset, count=g_count)
         l = response['items']
         count = len(l)
         ids = [d['id'] for d in l]
         usersData = users.getShortUsersByIds(set(ids))
         response['items'] = usersData
     except Exception as e:
         print('getBanned exception: ' + str(e))
         print(traceback.format_exc())
     return response, count
예제 #7
0
 def getDialogs(self, offset):
     api = vk.api()
     response = None
     usersData = None
     try:
         response = api.messages.getDialogs(offset=offset,
                                            count=g_LoadingElements)
         l = response["items"]
         #print('response dialogs: ' + json.dumps(response, indent=4))
         ids = set([d['message']['user_id'] for d in l])
         usersData = users.getShortUsersByIds(ids)
     except ConnectionError as e:
         raise e
     except Exception as e:
         print('get dialogs exception: ' + str(e))
     return {'response': response, 'users': usersData}
예제 #8
0
 def getGroups(self, userId, offset):
     api = vk.api()
     response = None
     usersData = None
     count = 0
     try:
         response = api.groups.get(user_id=userId,
                                   offset=offset,
                                   count=g_count)
         l = response['items']
         #print('groups.get response is: ' + json.dumps(response, indent=4))
         count = len(l)
         gl = [-id for id in l]
         response['items'] = gl
         usersData = users.getShortUsersByIds(set(gl))
     except ConnectionError as e:
         raise e
     except Exception as e:
         print('groups.get exception: ' + str(e))
     return {'response': response, 'users': usersData}, count
예제 #9
0
 def getUserInfo(self):
     if self.userInfo == None:
         usersInfo = users.getShortUsersByIds(set([self.userId]))
         if len(usersInfo) > 0:
             self.userInfo = usersInfo[0]
     return self.userInfo