Ejemplo n.º 1
0
def loop(maxTimeStep=1e9, withPolicy=None):
    # open today's file
    global currentFile
    global SIM
    global active_trading
    global max_spend_rolling
    currentFile = open(datetime.datetime.now().strftime("%m-%d-%Y.log"), "w")
    i = 1
    while (0 < i < maxTimeStep):
        if not SIM: time.sleep(60)
        if datetime.time(
                9, 31) <= datetime.datetime.now().time() <= datetime.time(
                    15, 57) or SIM:
            if i % 120 == 0 and not SIM:
                textMessage()

            try:
                balanceUpdater()
                update(withPolicy)
            except Exception as e:
                currentFile.write(
                    "\n\nReceived Exception at %s\n:%s\n" %
                    (datetime.datetime.now().strftime("%H %M %S"),
                     traceback.format_exc()))
        elif datetime.time(
                7, 00) <= datetime.datetime.now().time() < datetime.time(
                    9, 31):
            try:
                updatePreMarket()
            except Exception as e:
                currentFile.write(
                    "\n\nReceived Exception at %s\n:%s\n" %
                    (datetime.datetime.now().strftime("%H %M %S"),
                     traceback.format_exc()))
        elif datetime.time(
                15, 57) <= datetime.datetime.now().time() < datetime.time(
                    16, 30):
            dump()
            textMessage()
            dbPut(db)
            # refreshPolicies()
            cleanup()
            currentFile.close()
            logEOD()
            max_spend_rolling = max_spend
            exit(1)
        i += 1
        if i % 20 == 0 and not SIM:
            resetToken()
            currentFile.write("[20 min check in] Current Time: %s\n" %
                              datetime.datetime.now().strftime("%H %M %S"))
            dbPut(db)

    if SIM:
        currentFile.close()
        balanceUpdater(endofterm=True)
        ret = report()[0]
        #if ret > -2:
        #graphing.graph(withPolicy)
        return ret
Ejemplo n.º 2
0
async def on_app_cleanup(app: web.Application):
    """
    Defines the on-cleanup signal behavior for the application. The app parameter is
      important for aiohttp's Signal interface.

    :param app: The application instance the signal is being executed for.
    """
    # Cleaning up...
    app.logger.info("Cleaning up {{cookiecutter.app_name}}'s resources...")

    # Clean up the database resources
    db.cleanup()

    # Cleaned up!
    app.logger.info("{{cookiecutter.app_name}}'s resources were successfully cleaned up!")
Ejemplo n.º 3
0
def init_example():
    _logger.info("[Init-Example] creating new database engine")
    db.initialize()

    # Check if the table exist
    if not db.engine.dialect.has_table(db.engine, Example.__tablename__, db_option('schema')):
        _logger.info("[Init-Example] creating new database table: `example`")
        Example.__table__.create(bind=db.engine)

    _logger.info("[Init-Example] creating new rows in table: `example`")
    async def create_new_examples():
        async with transactional_session() as session:
            for i in range(1, 5):
                session.add(Example(name=f"Example #{i}"))
                session.commit()

    asyncio.get_event_loop().run_until_complete(create_new_examples())

    _logger.info("[Init-Example] cleaning up the database engine resources")
    db.cleanup()

    _logger.info("[Init-Example] done...")
Ejemplo n.º 4
0
dbCursor.execute(sql)
rows = dbCursor.fetchall()

cards = list()
for row in rows:
    cards.append(Card(card_name=row[0], card_effect=row[1]))

references = defaultdict(set)
for card in cards:
    matches = CARD_REFERENCE.findall(card.card_effect)
    for match in matches:
        match = match.replace('"', '')
        if match != card.card_name:  # card referencing itself isn't important, only adding references of other cards
            references[card.card_name].add(match)

print(references)
print(len(references))

directReferences = defaultdict(set)
for card_name, refs in references.items():
    for card in cards:
        if card.card_name in refs:
            directReferences[card_name].add(card.card_name)
            refs.remove(card.card_name)

print(directReferences)
print(len(directReferences))
print(references)

db.cleanup(dbConn, dbCursor)
Ejemplo n.º 5
0
    "4": ("Quit", leave_game),
}

def main():
    """Provide the main menu and options to the player.
    """
    while True:
        print ""
        for key in sorted(MENU.keys()):
            print "({0}): {1}".format(key, MENU[key][0])
        print ""
        choice = raw_input("> ")
        if choice.strip() in MENU:
            done = MENU[choice][1]()
            if done:
                # If any of the menu choices return truthy values, we're
                # done.
                return
        else:
            print "\nPlease type valid menu option.\n"



if __name__ == "__main__":
    # menu loop
    main()

    print "See you again soon!"
    # cleanup the database.
    db.cleanup()
Ejemplo n.º 6
0
    "4": ("Quit", leave_game),
}

def main():
    """Provide the main menu and options to the player.
    """
    while True:
        print ""
        for key in sorted(MENU.keys()):
            print "({0}): {1}".format(key, MENU[key][0])
        print ""
        choice = raw_input("> ")
        if choice.strip() in MENU:
            done = MENU[choice][1]()
            if done:
                # If any of the menu choices return truthy values, we're
                # done.
                return
        else:
            print "\nPlease type valid menu option.\n"



if __name__ == "__main__":
    # menu loop
    main()

    print "See you again soon!"
    # cleanup the database.
    db.cleanup()
Ejemplo n.º 7
0
def cleanup_database_connections(exc):
    cleanup()
Ejemplo n.º 8
0
	def init(self):
		if self._run:
			print "<<Stop Tarantool, Please"
			return -1
		cleanup(self._clean)
		print ">>Cleanup Tarantool"
Ejemplo n.º 9
0
	def init(self):
		cleanup(self._clean)
		print ">>Cleanup Redis"