Exemplo n.º 1
0
def client():
    """ Imports new data into the given database."""
    parser = _setup_commandline_arguments()
    arguments = parser.parse_args()

    engine = sqlalchemy.create_engine(arguments.database)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    Session.configure(bind=engine)
    session = Session()

    if arguments.list_accounts:
        names = [x.name for x in session.query(BankAccount).all()]
        print '\n'.join(names)

    if arguments.config and os.path.exists(arguments.config):
        fundscout.importer.config.configure_and_run(arguments.config)

    if arguments.csv and os.path.exists(arguments.csv):
        ba_name = fundscout.importer.guess_accountname_from_filename(
            arguments.csv)
        bankaccount = BankAccount.find_by_name(session, ba_name)
        if bankaccount is None:
            print 'Unable to find Bankaccount {}'.format(ba_name)
        else:
            print '{} transactions imported.'.format(
                fundscout.importer.import_csv(session,
                                              arguments.csv,
                                              bankaccount))

    sys.exit(0)
Exemplo n.º 2
0
 def testSetUp(cls):
     engine = sqlalchemy.create_engine('sqlite:///:memory:')
     Base.metadata.bind = engine
     Base.metadata.create_all(engine)
     Session.configure(bind=engine)