def _loadInventory(self, usr, pg, pgno): rows = pg.find( "form", action="process_safetydeposit.phtml?checksub=scan").find_all("tr") rows.pop(-1) # Last row contains no item for item in rows: stats = item.find_all("td") itemName = stats[1].b.text if itemName.find("(") != -1: itemName = itemName.split("(")[0] tmpItem = Item(itemName) tmpItem.img = stats[0].img['src'] tmpItem.desc = stats[2].text tmpItem.type = stats[3].text tmpItem.stock = stats[4].text tmpItem.id = stats[5].input['name'].split("[")[1].replace("]", "") tmpItem.pg = pgno tmpItem.usr = usr self.items[itemName] = tmpItem
def load(self): """Loads a user's inventory Queries the user's inventory, parses each item, and adds each item to the inventory. Note this class should not be used directly, but rather usr.inventory should be used to access a user's inventory. Parameters usr (User) - The user to load the inventory for Raises invalidUser parseException """ self.items = {} pg = self.usr.getPage( "http://www.neopets.com/objects.phtml?type=inventory") # Indicates an empty inventory if "You aren't carrying anything" in pg.content: return try: for row in pg.find_all( "td", "contentModuleContent")[1].table.find_all("tr"): for item in row.find_all("td"): name = item.text # Some item names contain extra information encapsulated in paranthesis if "(" in name: name = name.split("(")[0] tmpItem = Item(name) tmpItem.id = item.a['onclick'].split("(")[1].replace( ");", "") tmpItem.img = item.img['src'] tmpItem.desc = item.img['alt'] tmpItem.usr = self.usr self.items[name] = tmpItem except Exception: logging.getLogger("neolib.inventory").exception( "Unable to parse user inventory.", {'pg': pg}) raise parseException
def _loadInventory(self, usr, pg, pgno): rows = pg.find("form", action = "process_safetydeposit.phtml?checksub=scan").find_all("tr") rows.pop(-1) # Last row contains no item for item in rows: stats = item.find_all("td") itemName = stats[1].b.text if itemName.find("(") != -1: itemName = itemName.split("(")[0] tmpItem = Item(itemName) tmpItem.img = stats[0].img['src'] tmpItem.desc = stats[2].text tmpItem.type = stats[3].text tmpItem.stock = stats[4].text tmpItem.id = stats[5].input['name'].split("[")[1].replace("]", "") tmpItem.pg = pgno tmpItem.usr = usr self.items[itemName] = tmpItem