示例#1
0
    def _loadInventory(self, usr, owner, objID="", price="", pg=None):
        if objID and not price:
            raise invalidShop
        if not pg:
            if objID:
                pg = usr.getPage(
                    "http://www.neopets.com/browseshop.phtml?owner=" + owner +
                    "&buy_obj_info_id=" + objID + "&buy_cost_neopoints=" +
                    price)
            else:
                pg = usr.getPage(
                    "http://www.neopets.com/browseshop.phtml?owner=" + owner)

        # Checks for empty or invalid shop
        if "doesn't have a shop" in pg.content:
            raise invalidShop
        elif "not a valid shop" in pg.content:
            raise invalidShop
        elif "has changed price" in pg.content:
            raise invalidShop
        elif "no items for sale" in pg.content:
            return

        try:
            # If we were searching for an item, and it's not been bought, parse it first
            if objID and not "Item not found!" in pg.content:
                self._parseMainItem(pg, usr, owner)

                # Required to properly parse the rest of the inventory
                panel = pg.find("td", {
                    'width': '120'
                }).parent.parent.find_next("table")
            else:
                panel = pg.find("td", {'width': '120'}).parent.parent

            for row in panel.find_all("tr"):
                for item in row.find_all("td"):
                    tmpItem = UserShopFrontItem(item.b.text)

                    tmpItem.owner = owner
                    tmpItem.usr = usr
                    tmpItem.buyURL = item.a['href']
                    tmpItem.desc = item.img['title']
                    tmpItem.img = item.img['src']
                    tmpItem.price = item.text.split("Cost : ")[1]
                    tmpItem.stock = item.text.split(" in stock")[0].replace(
                        tmpItem.name, "")

                    self.items[item.b.text] = tmpItem
        except Exception:
            logging.getLogger("neolib.inventory").exception(
                "Unable to parse user shop front inventory.", {'pg': pg})
            raise parseException
示例#2
0
    def _parseMainItem(self, pg, usr, owner):
        panel = pg.find("td", {'width': '120'}).parent.parent

        item = panel.find_all("tr")[0].find_all("td")[0]

        tmpItem = UserShopFrontItem(item.b.text)

        tmpItem.owner = owner
        tmpItem.usr = usr
        tmpItem.buyURL = item.a['href']
        tmpItem.desc = item.img['title']
        tmpItem.img = item.img['src']
        tmpItem.price = item.text.split("Cost : ")[1]
        tmpItem.stock = item.text.split(" in stock")[0][-1:]

        self.items[item.b.text] = tmpItem