示例#1
0
def main():
    with open('user.json') as pwd_file:
        user_config = json.load(pwd_file)
    LOGDIR = user_config.get("logdir", DEFAULT_LOGDIR)

    """Set up logging in main, not global scope."""
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO) # - this is the line I needed to get logging to work!

    # So we also see logging to stderr so we can see it...
    stderr = logging.StreamHandler()
    stderr.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler())

    o_k = User(user_config['username'], user_config['password'])
    o_k.login()

    o_k.inventory.load()
    items = o_k.inventory.items
    print(items)
示例#2
0
def main():
    logger = logging.getLogger()

    stderr = logging.StreamHandler()
    stderr.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler())

    with open('user.json') as f:
        login = json.load(f)

    ok = User(login['username'], login['password'])
    if not ok.loggedIn:
        ok.login()

    nq = Neoquest(ok)

    current_state = nq.action('noop')
    print(current_state)
    current_state.map()

    raise Exception('Dummy error to drop into ipython shell')
示例#3
0
def main():
    with open('user.json') as f:
        user_config = json.load(f)
    LOGDIR = user_config.get("logdir", DEFAULT_LOGDIR)

    # Set up logging in main, not global scope.
    logger = logging.getLogger(__name__)
    logger.setLevel(
        logging.INFO)  # - this is the line I needed to get logging to work!

    fh = logging.FileHandler(os.path.join(LOGDIR, 'anacron_output.log'))
    fh.setLevel(logging.INFO)
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    fh.setFormatter(formatter)
    logger.addHandler(fh)

    # So we also see logging to stderr so we can see it...
    stderr = logging.StreamHandler()
    stderr.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler())

    ok = User(user_config['username'], user_config['password'])
    ok.login()

    # Start off your day by collecting interest at the bank
    ok.bank.load()
    ok.bank.collectInterest()
    logger.info('Stored/Bank NP before transactions: {}'.format(
        ok.bank.balance))
    logger.info('NP before transactions: {}'.format(ok.nps))

    # Then let's get do some dailies...
    # NOTE: doing these in this way guards from "Already did today!" exceptions
    for message in Daily.doDailies(ok, DAILY_LIST):
        logger.info(message)

    # Obviously, this script part doesn't really work anymore: but still,
    # for posterity,
    try_to_do_stocks(ok, logger)
示例#4
0
文件: base.py 项目: jmgilman/neolib2
class NeolibTestBase(unittest.TestCase):
    _usr = None

    susr = None

    def setUp(self):
        # Check if we have a previously saved user
        if NeolibTestBase.susr is not None:
            self._usr = NeolibTestBase.susr
            return

        print('')
        print('Welcome to the Neolib 2 test framework!')
        print('Please enter the below test configuration values:')

        username = input('Account username: '******'Account password: '******'Attempting to login to ' + self._usr.username)

            if self._usr.login():
                print('Successfully logged into ' + self._usr.username)

                # Store this user for later testing
                NeolibTestBase.susr = self._usr
            else:
                print('Failed to login to ' + self._usr.username +
                      '. Exiting...')
                exit()
        except Exception as e:
            print('Error while logging into ' + self._usr.username)
            print('Message: ' + str(e))
            print('Exiting...')
            exit()
示例#5
0
文件: base.py 项目: Yongyiw/neolib2
class NeolibTestBase(unittest.TestCase):
    _usr = None

    susr = None

    def setUp(self):
        # Check if we have a previously saved user
        if NeolibTestBase.susr is not None:
            self._usr = NeolibTestBase.susr
            return

        print('')
        print('Welcome to the Neolib 2 test framework!')
        print('Please enter the below test configuration values:')

        username = input('Account username: '******'Account password: '******'Attempting to login to ' + self._usr.username)

            if self._usr.login():
                print('Successfully logged into ' + self._usr.username)

                # Store this user for later testing
                NeolibTestBase.susr = self._usr
            else:
                print('Failed to login to ' + self._usr.username + '. Exiting...')
                exit()
        except Exception as e:
            print('Error while logging into ' + self._usr.username)
            print('Message: ' + str(e))
            print('Exiting...')
            exit()
示例#6
0
# Let the app set any additional arguments
parser = app.arguments(parser)

# Remove the app argument
del sys.argv[1]

# Parse the arguments
args = parser.parse_args()

# Setup the user instance
usr = User(args.username, args.password)

# Attempt to log the user in
print('Attempting to log ' + usr.username + ' into Neopets...')
try:
    if not usr.login():
        sys.exit('Failed to log ' + usr.username + ' into Neopets')
except Exception as e:
    sys.exit('Failed to log ' + usr.username + ' into Neopets with error: ' + str(e))

print(usr.username + ' was successfully logged into Neopets!')

# Let the application setup with the remaining arguments
print('Initializing application...')
app.usr = usr

try:
    app.setup(args)
except Exception as e:
    sys.exit('Failed initializing program with error: ' + str(e))