Exemplo n.º 1
0
 def __init__(self, username, password="", pin=None):
     # Neopets automatically converts all capitals in a username to lowercase
     self.username = username.lower()
     self.password = password
     self.pin = pin
     
     # Initialize
     self.inventory = UserInventory(self)
     self.shop = UserShop(self)
     self.bank = Bank(self)
     self.SDB = SDB(self)
     
     # Each User instance needs a unique session
     self.session = Page.newSession()
     
     # Default hooks
     self.hooks = []
     self.hooks.append(updateNPs)
     self.hooks.append(updatePet)
     self.hooks.append(autoLogin)
     
     # Config
     if not Configuration.loaded():
         if Configuration.initialize():
             self.__loadConfig()
     else:
         self.__loadConfig()
Exemplo n.º 2
0
def autoLogin(usr, pg):
    if "http://www.neopets.com/login/index.phtml" in pg.resp.url:
        # If auto login is enabled, try to log back in, otherwise raise an exception to let higher processes know the user is logged out.
        if usr.autoLogin:
            # Clear cookies
            usr.session = Page.newSession()
            if usr.login():
                # Request the page again now that the user is logged in
                pg = usr.getPage(pg.url, pg.postData, pg.vars)
            else:
                # Failed to login. Update status, log it, and raise an exception
                logging.getLogger("neolib.user").info("User was logged out. Failed to log back in.")
                raise logoutException
        else:
            # Auto login is not enabled. Update status and raise an exception.
            usr.loggedIn = False
            logging.getLogger("neolib.user").info("User was logged out. Auto login is disabled.")
            raise logoutException
        
    return [usr, pg]
Exemplo n.º 3
0
def autoLogin(usr, pg):
    if "http://www.neopets.com/login/index.phtml" in pg.resp.url:
        # If auto login is enabled, try to log back in, otherwise raise an exception to let higher processes know the user is logged out.
        if usr.autoLogin:
            # Clear cookies
            usr.session = Page.newSession()
            if usr.login():
                # Request the page again now that the user is logged in
                pg = usr.getPage(pg.url, pg.postData, pg.vars)
            else:
                # Failed to login. Update status, log it, and raise an exception
                logging.getLogger("neolib.user").info(
                    "User was logged out. Failed to log back in.")
                raise logoutException
        else:
            # Auto login is not enabled. Update status and raise an exception.
            usr.loggedIn = False
            logging.getLogger("neolib.user").info(
                "User was logged out. Auto login is disabled.")
            raise logoutException

    return [usr, pg]