def _onRatingsReceived(ratingsResponse): if ratingsResponse.isSuccess(): ratings = clanRatingsCtx.getDataObj(ratingsResponse.data) ratings = dict(((item.getClanDbID(), item) for item in ratings)) for clan in dataRef: clan['clan_ratings_data'] = ratings.get(clan['clan_id'], items.ClanRatingsData()) else: for clan in dataRef: clan['clan_ratings_data'] = items.ClanRatingsData() callback(clansResponse)
def __requestInvites(self, offset, count, isReset, callback): ctx = AccountInvitesCtx(accountDbID=self.__accountDbID, offset=offset, limit=count, statuses=self.__statuses, getTotalCount=isReset) result = yield self._requester.sendRequest(ctx, allowDelay=True) invites = ctx.getDataObj(result.data) self.__lastStatus = result.isSuccess() if isReset: self.__totalCount = ctx.getTotalCount(result.data) if result.isSuccess(): if len(invites) == 0 and not isReset: self.revertOffset() if len(invites) > 0: clansIDs = [item.getClanDbID() for item in invites] ctx = ClanRatingsCtx(clansIDs) result = yield self._requester.sendRequest(ctx, allowDelay=True) clanRatings = dict(((item.getClanDbID(), item) for item in ctx.getDataObj(result.data))) ctx = ClansInfoCtx(clansIDs) result = yield self._requester.sendRequest(ctx, allowDelay=True) clanInfo = dict(((item.getDbID(), item) for item in ctx.getDataObj(result.data))) for item in clanInfo.itervalues(): self.getUserName(item.getLeaderDbID()) def getSenderID(inviteItem): changerDbID = inviteItem.getChangerDbID() if changerDbID == 0: return inviteItem.getSenderDbID() return changerDbID for item in invites: senderID = getSenderID(item) temp = self.__senderNameMapping.get(senderID, set()) temp.add(item.getDbID()) self.__senderNameMapping[senderID] = temp self.__invitesCache = [ ClanPersonalInviteWrapper( invite, clanInfo.get(invite.getClanDbID(), items.ClanExtInfoData()), clanRatings.get(invite.getClanDbID(), items.ClanRatingsData()), self.getUserName(getSenderID(invite))) for invite in invites ] else: self.__invitesCache = [] else: self.__invitesCache = [] self.revertOffset() self.__rebuildMapping() self.syncUsersInfo() self.__isSynced = self.__lastStatus callback((self.__lastStatus, self.__invitesCache))
def requestClanRatings(self, callback): result = yield self.__requestClanRatings() if result: callback(result[0]) else: callback(items.ClanRatingsData())