예제 #1
0
    def test_make_intervals(self):

        with self.assertRaises(Exception):
            x = make_intervals(datetime(2016, 2, 24), timedelta(seconds=0), datetime(2016, 2, 27))

        x = make_intervals(datetime(2016, 2, 24), relativedelta(days=1), datetime(2016, 2, 26))
        self.assertEqual(x, [datetime(2016, 2, 24), datetime(2016, 2, 25), datetime(2016, 2, 26)])

        x = make_intervals(datetime(2016, 1, 31), relativedelta(months=1), datetime(2016, 4, 26))
        self.assertEqual(x, [datetime(2016, 1, 31), datetime(2016, 2, 29),
                             datetime(2016, 3, 31), datetime(2016, 4, 26)])
예제 #2
0
    year = datetime.now().year
    start = args.start if args.start else datetime(year, 1, 1)
    end = args.end if args.end else datetime(year+1, 1, 1)

    if args.verbose:
        print('Arguments:')
        print('\tgnucash_file:', args.gnucash_file, sep='\t')
        print('\troot_account:', args.root_account, sep='\t')
        print('\tstart:\t', start, sep='\t')
        print('\tend:\t', end, sep='\t')
        print('\toutput_format:', args.output_format, sep='\t')
        print('\tbeautify:', args.beautify, sep='\t')
        print('Results:')

    gnucash = GnuCash(GnuCashSqlite(args.gnucash_file))
    intervals = make_intervals(start, relativedelta(months=1), end)
    gnucash.load_balances(intervals)

    accounts = gnucash.get_accounts_by_name(args.root_account)
    if not accounts:
        print('ERROR: Account "' + args.root_account + '" does not exist')
        sys.exit(errno.EINVAL)

    if args.output_format == 'json':
        indent = None
        if args.beautify:
            indent = 2

        results = {'dates': [str(d) for d in intervals], 'accounts': accounts[0].get_structure()}
        print(json.dumps(results, indent=indent))
    else: