示例#1
0
    def collectMarketHistory(self):
        screeps = self.getScreepsAPI()
        market_history = screeps.market_history()

        if 'list' not in market_history:
            return

        for item in market_history['list']:
            item['id'] = item['_id']
            del item['_id']
            if item['type'] == 'market.fee':
                if 'extendOrder' in item['market']:
                    item['addAmount'] = item['market']['extendOrder']['addAmount']
                elif 'order' in item['market']:
                    item['orderType'] = item['market']['order']['type']
                    item['resourceType'] = item['market']['order']['resourceType']
                    item['price'] = item['market']['order']['price']
                    item['totalAmount'] = item['market']['order']['totalAmount']
                    item['roomName'] = item['market']['order']['roomName']
                else:
                    continue
                self.saveFee(item)
            else:
                item['resourceType'] = item['market']['resourceType']
                item['price'] = item['market']['price']
                item['totalAmount'] = item['market']['amount']
                if 'roomName' in item['market']:
                    item['roomName'] = item['market']['roomName']

                if 'targetRoomName' in item['market']:
                    item['targetRoomName'] = item['market']['targetRoomName']
                    user = screeps_service.getRoomOwner(item['targetRoomName'])
                    if user:
                        item['player'] = user
                        alliance = screeps_service.getAllianceFromUser(user)
                        if alliance:
                            item['alliance'] = alliance

                if 'npc' in item['market']:
                    item['npc'] = item['market']['npc']
                else:
                    item['npc'] = False
                self.saveOrder(item)
示例#2
0
    def collectMarketHistory(self, shard):
        screeps = self.getScreepsAPI()
        page = None
        failures = 0

        while True:

            market_history = screeps.market_history(page)

            if 'list' not in market_history:
                return

            for item in market_history['list']:
                if '_id' not in item:
                    continue

                item['id'] = item['_id']
                item['shard'] = shard
                del item['_id']
                if item['type'] == 'market.fee':
                    if 'extendOrder' in item['market']:
                        item['addAmount'] = item['market']['extendOrder'][
                            'addAmount']
                    elif 'order' in item['market']:
                        item['orderType'] = item['market']['order']['type']
                        item['resourceType'] = item['market']['order'][
                            'resourceType']
                        item['price'] = item['market']['order']['price']
                        item['totalAmount'] = item['market']['order'][
                            'totalAmount']
                        if 'roomName' in item['market']['order']:
                            item['roomName'] = item['market']['order'][
                                'roomName']
                    else:
                        continue
                    if self.saveFee(item):
                        failures = 0
                    else:
                        failures += 1
                else:
                    item['resourceType'] = item['market']['resourceType']
                    item['price'] = item['market']['price']
                    item['totalAmount'] = item['market']['amount']
                    if 'roomName' in item['market']:
                        item['roomName'] = item['market']['roomName']

                    if 'targetRoomName' in item['market']:
                        item['targetRoomName'] = item['market'][
                            'targetRoomName']
                        user = screeps_service.getRoomOwner(
                            item['targetRoomName'])
                        if user:
                            item['player'] = user
                            alliance = screeps_service.getAllianceFromUser(
                                user)
                            if alliance:
                                item['alliance'] = alliance

                    if 'npc' in item['market']:
                        item['npc'] = item['market']['npc']
                    else:
                        item['npc'] = False

                    if self.saveOrder(item):
                        failures = 0
                    else:
                        failures += 1

            if failures >= 10:
                print('Too many already captured records')
                return

            if 'hasMore' not in market_history:
                print('hasMore not present')
                return

            if not market_history['hasMore']:
                print('hasMore is false')
                return

            page = int(market_history['page']) + 1
            if page >= MAXPAGES:
                return
示例#3
0
    def collectMarketHistory(self, shard):
        screeps = self.getScreepsAPI()
        page = None
        failures = 0

        while True:

            market_history = screeps.market_history(page, shard)

            if 'list' not in market_history:
                return

            for item in market_history['list']:
                if '_id' not in item:
                    continue

                item['id'] = item['_id']
                item['shard'] = shard
                del item['_id']
                if item['type'] == 'market.fee':
                    if 'extendOrder' in item['market']:
                        item['addAmount'] = item['market']['extendOrder']['addAmount']
                    elif 'order' in item['market']:
                        item['orderType'] = item['market']['order']['type']
                        item['resourceType'] = item['market']['order']['resourceType']
                        item['price'] = item['market']['order']['price']
                        item['totalAmount'] = item['market']['order']['totalAmount']
                        if 'roomName' in item['market']['order']:
                            item['roomName'] = item['market']['order']['roomName']
                    else:
                        continue
                    if self.saveFee(item):
                        failures = 0
                    else:
                        failures += 1
                else:
                    item['resourceType'] = item['market']['resourceType']
                    item['price'] = item['market']['price']
                    item['totalAmount'] = item['market']['amount']
                    if 'roomName' in item['market']:
                        item['roomName'] = item['market']['roomName']

                    if 'targetRoomName' in item['market']:
                        item['targetRoomName'] = item['market']['targetRoomName']
                        user = screeps_service.getRoomOwner(item['targetRoomName'])
                        if user:
                            item['player'] = user
                            alliance = screeps_service.getAllianceFromUser(user)
                            if alliance:
                                item['alliance'] = alliance

                    if 'npc' in item['market']:
                        item['npc'] = item['market']['npc']
                    else:
                        item['npc'] = False

                    if self.saveOrder(item):
                        failures = 0
                    else:
                        failures += 1

            if failures >= 10:
                print('Too many already captured records')
                return

            if 'hasMore' not in market_history:
                print('hasMore not present')
                return

            if not market_history['hasMore']:
                print('hasMore is false')
                return

            page = int(market_history['page']) + 1
            if page >= MAXPAGES:
                return