Exemple #1
0
    def _parseActiveQuest(self, pg):
        try:
            dets = pg.find("td", "content").table.find_all("td")

            self.recipe = dets[1].text

            hour = dets[3].find_all("b")[1].text
            min = dets[3].find_all("b")[2].text
            self.time = (hour, min)

            imgs = pg.find("td",
                           "content").table.find_all("td")[5].find_all("img")
            items = pg.find("td",
                            "content").table.find_all("td")[5].find_all("b")

            self.items = []
            for i in range(len(items)):
                tmpItem = Item(items[i].text)
                tmpItem.img = imgs[i]['src']

                self.items.append(tmpItem)
        except Exception:
            logging.getLogger("neolib.quest").exception(
                "Failed to parse quest details", {'pg': pg})
            raise parseException
Exemple #2
0
    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
Exemple #3
0
    def __init__(self, usr):
        if not usr:
            raise invalidUser

        self.usr = usr
        pg = usr.getPage("http://www.neopets.com/island/kitchen.phtml")

        if "Sorry, too late" in pg.content:
            pg = usr.getPage("http://www.neopets.com/island/kitchen.phtml")

        if "there is a limit of" in pg.content:
            raise questLimitException

        if "still need some ingredients from you" in pg.content:
            self._parseActiveQuest(pg)

            usr.loadInventory()
            for item in self.items:
                if item.name in usr.inventory:
                    del (self.items[self.items.index(item)])
            return

        try:
            self.recipe = pg.find("td", "content").find(
                "input", {'name': 'food_desc'})['value']
        except Exception:
            logging.getLogger("neolib.quest").exception(
                "Failed to parse quest recipe", {'pg': pg})
            raise parseException

        form = pg.form(action="kitchen2.phtml")
        pg = form.submit()

        try:
            hour = pg.find("td", "content").find_all("b")[2].text
            min = pg.find("td", "content").find_all("b")[3].text

            self.time = (hour, min)

            self.items = []
            for item in pg.find("td", "content").table.find_all("td"):
                tmpItem = Item(item.b.text)
                tmpItem.img = item.img['src']

                self.items.append(tmpItem)
        except Exception:
            logging.getLogger("neolib.quest").exception(
                "Failed to parse quest details", {'pg': pg})
            raise parseException
Exemple #4
0
 def __init__(self, usr):
     if not usr:
         raise invalidUser
         
     self.usr = usr
     pg = usr.getPage("http://www.neopets.com/island/kitchen.phtml")
     
     if "Sorry, too late" in pg.content:
         pg = usr.getPage("http://www.neopets.com/island/kitchen.phtml")
     
     if "there is a limit of" in pg.content:
         raise questLimitException
     
     if "still need some ingredients from you" in pg.content:
         self._parseActiveQuest(pg)
         
         usr.loadInventory()
         for item in self.items:
             if item.name in usr.inventory:
                 del(self.items[self.items.index(item)])
         return
         
     try:
         self.recipe = pg.find("td", "content").find("input", {'name': 'food_desc'})['value']
     except Exception:
         logging.getLogger("neolib.quest").exception("Failed to parse quest recipe", {'pg': pg})
         raise parseException
         
     form = pg.form(action="kitchen2.phtml")
     pg = form.submit()
     
     try:
         hour = pg.find("td", "content").find_all("b")[2].text
         min = pg.find("td", "content").find_all("b")[3].text
         
         self.time = (hour, min)
         
         self.items = []
         for item in pg.find("td", "content").table.find_all("td"):
             tmpItem = Item(item.b.text)
             tmpItem.img = item.img['src']
             
             self.items.append(tmpItem)
     except Exception:
         logging.getLogger("neolib.quest").exception("Failed to parse quest details", {'pg': pg})
         raise parseException
    def __init__(self, pg, usr):
        self.usr = usr

        try:
            items = pg.find(
                "td", "contentModuleHeaderAlt").parent.parent.find_all("tr")
            items.pop(0)

            self.items = []
            for item in items:
                tmpItem = Item(item.find_all("td")[1].text)

                tmpItem.owner = item.td.a.text
                tmpItem.location = item.td.a['href']
                tmpItem.stock = item.find_all("td")[2].text
                tmpItem.price = item.find_all("td")[3].text.replace(
                    " NP", "").replace(",", "")
                tmpItem.id = tmpItem.location.split(
                    "buy_obj_info_id=")[1].split("&")[0]

                self.items.append(tmpItem)
        except Exception:
            logging.getLogger("neolib.shop").exception(
                "Unable to parse shop wizard results.", {'pg': pg})
            raise parseException
Exemple #6
0
 def _parseActiveQuest(self, pg):
     try:
         dets = pg.find("td", "content").table.find_all("td")
         
         self.recipe = dets[1].text
         
         hour = dets[3].find_all("b")[1].text
         min = dets[3].find_all("b")[2].text
         self.time = (hour, min)
         
         imgs = pg.find("td", "content").table.find_all("td")[5].find_all("img")
         items = pg.find("td", "content").table.find_all("td")[5].find_all("b")
         
         self.items = []
         for i in range(len(items)):
             tmpItem = Item(items[i].text)
             tmpItem.img = imgs[i]['src']
             
             self.items.append(tmpItem)
     except Exception:
         logging.getLogger("neolib.quest").exception("Failed to parse quest details", {'pg': pg})
         raise parseException
Exemple #7
0
 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
Exemple #8
0
    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
Exemple #9
0
 def __init__(self, pg, usr):
     self.usr = usr
     
     try:
         items = pg.find("td", "contentModuleHeaderAlt").parent.parent.find_all("tr")
         items.pop(0)
         
         self.items = []
         for item in items:
             tmpItem = Item(item.find_all("td")[1].text)
             
             tmpItem.owner = item.td.a.text
             tmpItem.location = item.td.a['href']
             tmpItem.stock = item.find_all("td")[2].text
             tmpItem.price = item.find_all("td")[3].text.replace(" NP", "").replace(",", "")
             tmpItem.id = tmpItem.location.split("buy_obj_info_id=")[1].split("&")[0]
             
             self.items.append(tmpItem)
     except Exception:
         logging.getLogger("neolib.shop").exception("Unable to parse shop wizard results.", {'pg': pg})
         raise parseException