def runTest(self):
        s = TestData.data["session"]

        item = ItemDatabase.getItemFromName("olive")
        r = ItemDescriptionRequest(s, item["descId"])
        itemData = r.doRequest()
        self.assertEquals(itemData["isCookingIngredient"], True)
        self.assertEquals(itemData["isCocktailcraftingIngredient"], True)
        self.assertEquals(itemData["image"], "olive.gif")
        self.assertEquals(itemData["autosell"], 35)
        self.assertEquals(itemData["type"], "food")

        item = ItemDatabase.getItemFromName("furry fur")
        r = ItemDescriptionRequest(s, item["descId"])
        itemData = r.doRequest()
        self.assertEquals(itemData["isMeatsmithingComponent"], True)
        self.assertEquals(itemData["image"], "furfur.gif")
        self.assertEquals(itemData["autosell"], 129)

        item = ItemDatabase.getItemFromName("baconstone")
        r = ItemDescriptionRequest(s, item["descId"])
        itemData = r.doRequest()
        self.assertEquals(itemData["image"], "baconstone.gif")
        self.assertEquals(itemData["autosell"], 500)

        # Test a haiku item -- these description pages are formatted differently.
        r = ItemDescriptionRequest(s, 435365663)
        itemData = r.doRequest()
        self.assertEquals(itemData["name"], "little round pebble")
        self.assertEquals(itemData["autosell"], 45)
        self.assertEquals(itemData["type"], "off-hand item")
Ejemplo n.º 2
0
    def parseResponse(self):
        itemsDontMakeFoodPattern = PatternManager.getOrCompilePattern(
            'itemsDontCook')
        dontHaveSkillPattern = PatternManager.getOrCompilePattern(
            'dontHaveSkillToCook')
        dontHaveItemsPattern = PatternManager.getOrCompilePattern(
            'dontHaveItemsForCook')
        dontHaveAdventuresPattern = PatternManager.getOrCompilePattern(
            'dontHaveAdventuresToCook')
        chefExplosionPattern = PatternManager.getOrCompilePattern(
            'chefExplosion')
        # Check for errors.
        if itemsDontMakeFoodPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make food. The submitted ingredients do not cook together.",
                Error.RECIPE_NOT_FOUND)
        elif dontHaveSkillPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make food. We are not skilled enough.",
                Error.SKILL_NOT_FOUND)
        elif dontHaveItemsPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make food. You don't have all of the items you are trying to cook.",
                Error.ITEM_NOT_FOUND)
        elif dontHaveAdventuresPattern.search(self.responseText):
            raise Error.Error(
                "Unable to cook food(s). We don't have enough adventures.",
                Error.NOT_ENOUGH_ADVENTURES)

        # Find the items attached to the message.
        singleItemPattern = PatternManager.getOrCompilePattern(
            'acquireSingleItem')
        match = singleItemPattern.search(self.responseText)
        if match:
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = 1
        else:
            multiItemPattern = PatternManager.getOrCompilePattern(
                'acquireMultipleItems')
            match = multiItemPattern.search(self.responseText)
            if match:
                descId = int(match.group(1))
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    descId, self.session)
                quantity = int(match.group(2).replace(',', ''))
                item["quantity"] = quantity
            else:
                raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)

        # Check for an explosion
        if chefExplosionPattern.search(self.responseText):
            self.responseData["explosion"] = 1
            #TODO: Remove the items that came from the explosion

        self.responseData["food"] = item
Ejemplo n.º 3
0
    def parseResponse(self):
        itemsDontMakeCocktailPattern = PatternManager.getOrCompilePattern(
            'itemsDontMakeCocktail')
        dontHaveSkillPattern = PatternManager.getOrCompilePattern(
            'dontHaveSkillToMixCocktail')
        dontHaveItemsPattern = PatternManager.getOrCompilePattern(
            'dontHaveItemsForThatCocktail')
        dontHaveAdventuresPattern = PatternManager.getOrCompilePattern(
            'dontHaveAdventuresToMixCocktail')

        # Check for errors.
        if itemsDontMakeCocktailPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make cocktail. The submitted ingredients do not mix together.",
                Error.RECIPE_NOT_FOUND)
        elif dontHaveSkillPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make cocktail. We are not skilled enough.",
                Error.SKILL_NOT_FOUND)
        elif dontHaveItemsPattern.search(self.responseText):
            raise Error.Error(
                "Unable to make cocktail. You don't have all of the items you are trying to mix.",
                Error.ITEM_NOT_FOUND)
        elif dontHaveAdventuresPattern.search(self.responseText):
            raise Error.Error(
                "Unable to mix drink(s). We don't have enough adventures.",
                Error.NOT_ENOUGH_ADVENTURES)

        # Find the items attached to the message.
        singleItemPattern = PatternManager.getOrCompilePattern(
            'acquireSingleItem')
        match = singleItemPattern.search(self.responseText)
        if match:
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = 1
        else:
            multiItemPattern = PatternManager.getOrCompilePattern(
                'acquireMultipleItems')
            match = multiItemPattern.search(self.responseText)
            if match:
                descId = int(match.group(1))
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    descId, self.session)
                quantity = int(match.group(2).replace(',', ''))
                item["quantity"] = quantity
            else:
                raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)

        self.responseData["booze"] = item
Ejemplo n.º 4
0
    def parseResponse(self):
        noWokAccess = PatternManager.getOrCompilePattern('noWokAccess')
        itemsDontMakeFoodPattern = PatternManager.getOrCompilePattern(
            'dontHaveItemsForWok')
        dontHaveSkillPattern = PatternManager.getOrCompilePattern(
            'dontHaveSkillForWok')
        dontHaveAdventuresPattern = PatternManager.getOrCompilePattern(
            'dontHaveAdventuresForWok')
        # Check for errors.
        if noWokAccess.search(self.responseText):
            raise Error.Error(
                "Unable to use the Wok of Ages. I can't get to the Wok!",
                Error.RECIPE_NOT_FOUND)
        elif dontHaveSkillPattern.search(self.responseText):
            raise Error.Error(
                "Unable to use the Wok of Ages. I am not skilled enough.",
                Error.SKILL_NOT_FOUND)
        elif itemsDontMakeFoodPattern.search(self.responseText):
            raise Error.Error(
                "Unable to use the Wok of Ages. Invalid ingredients.",
                Error.ITEM_NOT_FOUND)
        elif dontHaveAdventuresPattern.search(self.responseText):
            raise Error.Error(
                "Unable to use the Wok of Agles. I don't have enough adventures.",
                Error.NOT_ENOUGH_ADVENTURES)

        # Find the items attached to the message.
        singleItemPattern = PatternManager.getOrCompilePattern(
            'acquireSingleItem')
        match = singleItemPattern.search(self.responseText)
        if match:
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = 1
        else:
            multiItemPattern = PatternManager.getOrCompilePattern(
                'acquireMultipleItems')
            match = multiItemPattern.search(self.responseText)
            if match:
                descId = int(match.group(1))
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    descId, self.session)
                quantity = int(match.group(2).replace(',', ''))
                item["quantity"] = quantity
            else:
                raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)

        self.responseData["wok"] = item
    def parseResponse(self):
        item = ItemDatabase.getOrDiscoverItemFromId(int(self.itemId), self.session)
        mallPricesUnlimitedPattern = PatternManager.getOrCompilePattern('mallPricesUnlimited')

        for match in mallPricesUnlimitedPattern.finditer(self.responseText):
            unlimited = []
            price = {"price" : match.group(1).replace(",", ""), "count" : match.group(2).replace(",", "")}
            unlimited.append(price)
            price = {"price" : match.group(3).replace(",", ""), "count" : match.group(4).replace(",", "")}
            unlimited.append(price)       
            price = {"price" : match.group(5).replace(",", ""), "count" : match.group(6).replace(",", "")}
            unlimited.append(price)        
            price = {"price" : match.group(7).replace(",", ""), "count" : match.group(8).replace(",", "")}
            unlimited.append(price)             
            
            item["unlimited"] = unlimited

        mallPricesLimitedPattern = PatternManager.getOrCompilePattern('mallPricesLimited')

        for match in mallPricesLimitedPattern.finditer(self.responseText):            
            limited = []
            print 
            price = {"price" : match.group(1).replace(",", ""), "limit" : match.group(2).replace(",", ""), "count" : match.group(3).replace(",", "")}
            limited.append(price)
            price = {"price" : match.group(4).replace(",", ""), "limit" : match.group(5).replace(",", ""), "count" : match.group(6).replace(",", "")}
            limited.append(price)
            price = {"price" : match.group(7).replace(",", ""), "limit" : match.group(8).replace(",", ""), "count" : match.group(9).replace(",", "")}
            limited.append(price)
            
            item["limited"] = limited

        self.responseData["item"] = item
Ejemplo n.º 6
0
    def parseResponse(self):
        cantPulverizePattern = PatternManager.getOrCompilePattern(
            'cantPulverizeItem')
        if cantPulverizePattern.search(self.responseText) != None:
            item = ItemDatabase.getOrDiscoverItemFromId(
                self.itemId, self.session)
            raise Error.Error(
                "'%s' is not an item that can be pulverized." % item["name"],
                Error.WRONG_KIND_OF_ITEM)

        notEnoughItemsPattern = PatternManager.getOrCompilePattern(
            'notEnoughItems')
        if notEnoughItemsPattern.search(self.responseText) != None:
            item = ItemDatabase.getOrDiscoverItemFromId(
                self.itemId, self.session)
            if self.quantity == 1:
                itemStr = item["name"]
            else:
                itemStr = item["plural"]
            raise Error.Error(
                "You do not have %s (%s)." % (itemStr, self.quantity),
                Error.ITEM_NOT_FOUND)

        items = []

        singleItemPattern = PatternManager.getOrCompilePattern(
            'acquireSingleItem')
        for match in singleItemPattern.finditer(self.responseText):
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = 1
            items.append(item)

        multiItemPattern = PatternManager.getOrCompilePattern(
            'acquireMultipleItems')
        for match in multiItemPattern.finditer(self.responseText):
            descId = int(match.group(1))
            quantity = int(match.group(2).replace(',', ''))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = quantity
            items.append(item)

        self.responseData["results"] = items
Ejemplo n.º 7
0
    def parseResponse(self):
        wrongProfessionPattern = PatternManager.getOrCompilePattern(
            'wrongStillProfession')
        invalidItemPattern = PatternManager.getOrCompilePattern(
            'invalidStillItem')
        ItemNotFoundPattern = PatternManager.getOrCompilePattern(
            'stillItemNotFound')
        maxLimitPattern = PatternManager.getOrCompilePattern('stillMaxLimit')

        if wrongProfessionPattern.search(self.responseText):
            raise Error.Error("You aren't a Disco Bandit or Accordion Thief.",
                              Error.USER_IS_WRONG_PROFESSION)
        if invalidItemPattern.search(self.responseText):
            raise Error.Error("You can\'t improve that item.",
                              Error.INVALID_ITEM)
        if ItemNotFoundPattern.search(self.responseText):
            raise Error.Error("Not enough of that item.", Error.ITEM_NOT_FOUND)
        if maxLimitPattern.search(self.responseText):
            raise Error.Error("Still can\'t be used anymore today.",
                              Error.LIMIT_REACHED)

        # Find the items attached to the message.
        singleItemPattern = PatternManager.getOrCompilePattern(
            'acquireSingleItem')
        match = singleItemPattern.search(self.responseText)
        if match:
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = 1
        else:
            multiItemPattern = PatternManager.getOrCompilePattern(
                'acquireMultipleItems')
            match = multiItemPattern.search(self.responseText)
            if match:
                descId = int(match.group(1))
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    descId, self.session)
                quantity = int(match.group(2).replace(',', ''))
                item["quantity"] = quantity
            else:
                raise Error.Error("Unknown error.", Error.REQUEST_GENERIC)

        self.responseData["item"] = item
Ejemplo n.º 8
0
def parseItemsReceived(text, session):
    items = []

    singleItemPattern = PatternManager.getOrCompilePattern('acquireSingleItem')
    for match in singleItemPattern.finditer(text):
        descId = int(match.group(1))
        item = ItemDatabase.getOrDiscoverItemFromDescId(descId, session)
        item["quantity"] = 1
        items.append(item)

    multiItemPattern = PatternManager.getOrCompilePattern(
        'acquireMultipleItems')
    for match in multiItemPattern.finditer(text):
        descId = int(match.group(1))
        quantity = int(match.group(2).replace(',', ''))
        item = ItemDatabase.getOrDiscoverItemFromDescId(descId, session)
        item["quantity"] = quantity
        items.append(item)

    return items
Ejemplo n.º 9
0
    def parseResponse(self):
        items = []

        singleItemPattern = PatternManager.getOrCompilePattern(
            'acquireSingleItem')
        for match in singleItemPattern.finditer(self.responseText):
            descId = int(match.group(1))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = 1
            items.append(item)

        multiItemPattern = PatternManager.getOrCompilePattern(
            'acquireMultipleItems')
        for match in multiItemPattern.finditer(self.responseText):
            descId = int(match.group(1))
            quantity = int(match.group(2).replace(',', ''))
            item = ItemDatabase.getOrDiscoverItemFromDescId(
                descId, self.session)
            item["quantity"] = quantity
            items.append(item)

        self.responseData["results"] = items
Ejemplo n.º 10
0
    def parseResponse(self):
        super(InventoryRequest, self).parseResponse()

        items = []
        for itemId, quantity in self.jsonData.iteritems():
            if self.ignoreItemDatabase:
                item = {}
                item["id"] = int(itemId)
                item["quantity"] = int(quantity)
                items.append(item)
            else:
                item = ItemDatabase.getOrDiscoverItemFromId(
                    int(itemId), self.session)
                item["quantity"] = int(quantity)
            items.append(item)

        self.responseData["items"] = items
Ejemplo n.º 11
0
    def parseResponse(self):
        menuItemPattern = PatternManager.getOrCompilePattern('menuItem')
        cannotGoPattern = PatternManager.getOrCompilePattern('userShouldNotBeHere')

        if cannotGoPattern.search(self.responseText):
            raise Error.Error("You cannot reach that cafe.", Error.INVALID_LOCATION)

        items = []
        for match in menuItemPattern.finditer(self.responseText):
            descId = match.group(2)
            if descId.isdigit():
                descId = int(descId)
            item = ItemDatabase.getItemFromDescId(descId)
            items.append(item)

        if len(items) == 0:
            raise Error.Error("Retrieved an Empty Menu", Error.REQUEST_GENERIC)

        self.responseData["menu"] = items
Ejemplo n.º 12
0
    def parseResponse(self):
        """
        Searches backoffice.php for item name, quantity, price, limit, and ID.
        Returns the items with the usual keys in the item data base along with:

            quantity -- The number of the item in your mall store.
               price -- The price of the item in your mall store.
               limit -- The limit on the item in your mall store.
            cheapest -- The cheapest in mall. This includes limited items, use at own risk.
             orderId -- Item order in your store. 0 is the first listed and so on.
             
        RegExp match notes: Group 3,6,9, and 11 are garbage HTML data.
        """
        storeInventoryPattern = PatternManager.getOrCompilePattern(
            'storeInventory')

        items = []
        for match in storeInventoryPattern.finditer(self.responseText):
            descId = match.group(1)
            orderId = match.group(2)
            name = match.group(4)
            quantity = match.group(5)
            itemID = int(match.group(7))
            item = ItemDatabase.getOrDiscoverItemFromId(itemID, self.session)
            price = match.group(8)
            limit = int(match.group(10))
            cheapest = int(match.group(12))

            item["orderId"] = orderId
            item["quantity"] = quantity
            item["price"] = price
            item["limit"] = limit
            item["cheapest"] = cheapest
            items.append(item)

        self.responseData["items"] = items
Ejemplo n.º 13
0
 def runTest(self):
     ItemDatabase.init()
Ejemplo n.º 14
0
    def parseResponse(self):
        """
        Parses through the response and constructs an array of messages.
        Each message is represented as a dictionary with the following
        keys:

              id -- The integer identifier for the message.
          userId -- The ID of the user who sent or received this message.
        userName -- The name of the user who sent or received this message.
            date -- The date the message was sent as a datetime object.
            text -- The contents of the message.
           items -- An array of items attached to the message.
            meat -- The amount of meat sent with the message.
        """

        fullMessagePattern = PatternManager.getOrCompilePattern('fullMessage')
        whitespacePattern = PatternManager.getOrCompilePattern('whitespace')
        singleItemPattern = PatternManager.getOrCompilePattern(
            'acquireSingleItem')
        multiItemPattern = PatternManager.getOrCompilePattern(
            'acquireMultipleItems')
        meatPattern = PatternManager.getOrCompilePattern('gainMeat')
        brickPattern = PatternManager.getOrCompilePattern('brickMessage')
        coffeePattern = PatternManager.getOrCompilePattern('coffeeMessage')
        candyHeartPattern = PatternManager.getOrCompilePattern(
            'candyHeartMessage')

        messages = []

        for message in fullMessagePattern.finditer(self.responseText):
            messageId = int(message.group(1))
            userId = int(message.group(2))
            userName = message.group(3).strip()

            dateStr = message.group(4).strip()
            try:
                date = datetime.strptime(dateStr, "%A, %B %d, %Y, %I:%M%p")
            except ValueError:
                date = dateStr

            rawText = message.group(5).strip()
            index = rawText.find('<center')
            if index >= 0:
                text = rawText[:index].strip()
            else:
                text = rawText.strip()

            # Get rid of extraneous spaces, tabs, or new lines.
            text = text.replace("\r\n", "\n")
            text = whitespacePattern.sub(' ', text)
            text = text.replace("<br />\n", "\n")
            text = text.replace("<br/>\n", "\n")
            text = text.replace("<br>\n", "\n")
            text = text.replace("\n<br />", "\n")
            text = text.replace("\n<br/>", "\n")
            text = text.replace("\n<br>", "\n")
            text = text.replace("<br />", "\n")
            text = text.replace("<br/>", "\n")
            text = text.replace("<br>", "\n")
            text = text.strip()

            # KoL encodes all of the HTML entities in the message. Let's decode them to get the real text.
            text = StringUtils.htmlEntityDecode(text)

            m = {
                "id": messageId,
                "userId": userId,
                "userName": userName,
                "date": date,
                "text": text
            }

            # Find the items attached to the message.
            items = []
            for match in singleItemPattern.finditer(rawText):
                descId = int(match.group(1))
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    descId, self.session)
                item["quantity"] = 1
                items.append(item)
            for match in multiItemPattern.finditer(rawText):
                descId = int(match.group(1))
                quantity = int(match.group(2).replace(',', ''))
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    descId, self.session)
                item["quantity"] = quantity
                items.append(item)
            m["items"] = items

            # Find how much meat was attached to the message.
            meat = 0
            meatMatch = meatPattern.search(rawText)
            if meatMatch:
                meat = int(meatMatch.group(1).replace(',', ''))
            m["meat"] = meat

            # Handle special messages.
            if brickPattern.search(rawText):
                m["messageType"] = "brick"
            elif coffeePattern.search(rawText):
                m["messageType"] = "coffeeCup"
            elif candyHeartPattern.search(rawText):
                m["messageType"] = "candyHeart"
            else:
                m["messageType"] = "normal"

            messages.append(m)

        self.responseData["kmails"] = messages
Ejemplo n.º 15
0
    def parseResponse(self):
        hatPattern = PatternManager.getOrCompilePattern("currentHat")
        weaponPattern = PatternManager.getOrCompilePattern("currentWeapon")
        offhandPattern = PatternManager.getOrCompilePattern("currentOffhand")
        shirtPattern = PatternManager.getOrCompilePattern("currentShirt")
        pantsPattern = PatternManager.getOrCompilePattern("currentPants")
        accPattern = PatternManager.getOrCompilePattern("currentAcc")
        acc1Pattern = PatternManager.getOrCompilePattern("currentAcc1")
        acc2Pattern = PatternManager.getOrCompilePattern("currentAcc2")
        acc3Pattern = PatternManager.getOrCompilePattern("currentAcc3")
        familiarPattern = PatternManager.getOrCompilePattern("currentFam")

        hatText = hatPattern.search(self.responseText)
        if hatText:
            self.responseData[
                "hat"] = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(hatText.group(1)), self.session)

        weaponText = weaponPattern.search(self.responseText)
        if weaponText:
            self.responseData[
                "weapon"] = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(weaponText.group(1)), self.session)

        offhandText = offhandPattern.search(self.responseText)
        if offhandText:
            self.responseData[
                "offhand"] = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(offhandText.group(1)), self.session)

        shirtText = shirtPattern.search(self.responseText)
        if shirtText:
            self.responseData[
                "shirt"] = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(shirtText.group(1)), self.session)

        pantsText = pantsPattern.search(self.responseText)
        if pantsText:
            self.responseData[
                "pants"] = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(pantsText.group(1)), self.session)

        accessories = []
        accText = accPattern.search(self.responseText)
        if accText:
            for match in accPattern.finditer(self.responseText):
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(match.group(1)), self.session)
                item["slot"] = 0
                accessories.append(item)
        else:
            acc1Text = acc1Pattern.search(self.responseText)
            if acc1Text:
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(acc1Text.group(1)), self.session)
                item["slot"] = 1
                accessories.append(item)
            acc2Text = acc2Pattern.search(self.responseText)
            if acc2Text:
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(acc2Text.group(1)), self.session)
                item["slot"] = 2
                accessories.append(item)
            acc3Text = acc3Pattern.search(self.responseText)
            if acc3Text:
                item = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(acc3Text.group(1)), self.session)
                item["slot"] = 3
                accessories.append(item)
        if len(accessories) > 0:
            self.responseData["acc"] = accessories

        famText = familiarPattern.search(self.responseText)
        if famText:
            self.responseData[
                "familiar"] = ItemDatabase.getOrDiscoverItemFromDescId(
                    int(famText.group(1)), self.session)
Ejemplo n.º 16
0
 def parseResponse(self):
     """
     Returns a dict in which 'results' references an array of dicts.  If the 
     search included items only, each dict would have the following item keys:
         descId (always)
         id (always)
         image (always)
         name (always)
     and sometime, depending on the kind of item,
         adventuresGained
         autosell
         drunkenness
         fullness
         isBounty
         isCandy
         isCombatReusable
         isCombatUsable
         isMultiUsable
         isReusable
         isSphere
         isUsable
         isUsableOnOthers
         isZappable
         moxieGained
         muscleGained
         mysticalityGained
         npcPrice
         npcStoreId
         numPackageItems
         plural
         power
         quality
         requiredMoxie
         requiredMuscle
         requiredMysticality
         spleen
         type
     If the search included shops, the dicts would have the following
     additional keys:
         hitLimit (if the item's limit has been hit by the session character)
         limit (if the item is limited per day)
         price
         quantity
         storeId
         storeName
     """
     items = []
     itemMatchPattern = self.getPattern('mallItemSearchResult')
     itemDetailsPattern = self.getPattern('mallItemSearchDetails')
     itemHeaderPattern = self.getPattern('mallItemHeader')
     if self.justItems:
         for itemMatch in itemHeaderPattern.finditer(self.responseText):
             itemId = int(itemMatch.group(1))
             try:
                 item = ItemDatabase.getItemFromId(itemId)
                 items.append(item)
             except Error.Error, inst:
                 if inst.code == Error.ITEM_NOT_FOUND:
                     Report.info(
                         "itemdatabase",
                         "Unrecognized item found in mall search: {0}".
                         format(itemId), inst)
                 else:
                     raise inst
Ejemplo n.º 17
0
             items.append(item)
         except Error.Error, inst:
             if inst.code == Error.ITEM_NOT_FOUND:
                 Report.info(
                     "itemdatabase",
                     "Unrecognized item found in mall search: {0}".
                     format(itemId), inst)
             else:
                 raise inst
 else:
     for itemMatch in itemMatchPattern.finditer(self.responseText):
         matchText = itemMatch.group(1)
         match = itemDetailsPattern.search(matchText)
         itemId = int(match.group('itemId'))
         try:
             item = ItemDatabase.getItemFromId(itemId)
             item["price"] = int(match.group('price').replace(',', ''))
             item["storeId"] = int(match.group('storeId'))
             storeName = match.group('storeName').replace('<br>', ' ')
             item['storeName'] = self.HTML_PARSER.unescape(storeName)
             item["quantity"] = int(
                 match.group('quantity').replace(',', ''))
             limit = match.group('limit').replace(',', '')
             if len(limit) > 0:
                 limit = int(limit)
                 item["limit"] = limit
             if matchText.find('limited"') >= 0:
                 item["hitLimit"] = True
             items.append(item)
         except Error.Error, inst:
             if inst.code == Error.ITEM_NOT_FOUND:
Ejemplo n.º 18
0
    def parseResponse(self):
        """
        Parse each different kind of trade. Each trade offer or offer and response is represented as a dictionary with following keys:
        
        tradeID:        The ID of the trade.
        tradeType:      The type of the trade - OUTGOING, INCOMING, etc.
        playerID:       The ID of the other player involved in this trade.
        playerName:     The name of the other player involved in this trade.
        incomingitems:  An array of items being offered to you in the format of a dictionary with keys itemID, quantity, and itemName.
        outgoingitems:  An array of items being offered to the other player in the format of a dictionary with keys itemID, quantity, and itemName.
        incomingmeat:   The amount of meat being offered by the other player.
        outgoingmeat:   The amount of meat being offered to the other player.
        message:        The message or note attached to the trade.
        """
        outgoingResponsePattern = PatternManager.getOrCompilePattern(
            'tradePendingResponseOutgoing')
        incomingResponsePattern = PatternManager.getOrCompilePattern(
            'tradePendingResponseIncoming')
        outgoingPattern = PatternManager.getOrCompilePattern(
            'tradePendingOfferOutgoing')
        incomingPattern = PatternManager.getOrCompilePattern(
            'tradePendingOfferIncoming')
        messagePattern = PatternManager.getOrCompilePattern('tradeMessage')
        itemPattern = PatternManager.getOrCompilePattern('tradeItem')

        tradeoffers = []

        iters = [
            incomingPattern.finditer(self.responseText),
            outgoingPattern.finditer(self.responseText),
            incomingResponsePattern.finditer(self.responseText),
            outgoingResponsePattern.finditer(self.responseText)
        ]
        for matchset in iters:
            for trade in matchset:
                tradeType = iters.index(matchset) + 1
                tradeID = trade.group('tradeid')
                playerID = trade.group('playerid')
                playerName = trade.group('playername')
                try:
                    incomingitems = trade.group(
                        'incomingitems')  #To be formatted later
                except:
                    incomingitems = None
                try:
                    outgoingitems = trade.group(
                        'outgoingitems')  #To be formatted later
                except:
                    outgoingitems = None
                try:
                    incomingmeat = int(trade.group('incomingmeat'))
                except:
                    incomingmeat = None
                try:
                    outgoingmeat = int(trade.group('outgoingmeat'))
                except:
                    outgoingmeat = None
                message = trade.group('message')  #To be formatted later
                iitems = []
                if incomingitems != None:
                    for item in itemPattern.finditer(incomingitems):
                        iitems.append({
                            'itemID':
                            item.group(
                                ItemDatabase.getItemFromDescId(
                                    item.group('itemdescid'))),
                            'itemName':
                            item.group(item.group('itemname')),
                            'quantity':
                            item.group('quantity')
                        })
                oitems = []
                if outgoingitems != None:
                    for item in itemPattern.finditer(outgoingitems):
                        oitems.append({
                            'itemID':
                            item.group(
                                ItemDatabase.getItemFromDescId(
                                    item.group('itemdescid'))),
                            'itemName':
                            item.group(item.group('itemname')),
                            'quantity':
                            item.group('quantity')
                        })
                try:
                    message = messagePattern.search(message).group('message')
                except:
                    message = None
                tradeoffers.append({
                    'tradeID': tradeID,
                    'tradeType': tradeType,
                    'playerID': playerID,
                    'playerName': playerName,
                    'incomingitems': iitems,
                    'outgoingitems': oitems,
                    'incomingmeat': incomingmeat,
                    'outgoingmeat': outgoingmeat,
                    'message': message,
                })
        self.responseData['trades'] = tradeoffers