ledger.py (875B) - raw


      1 #!/usr/bin/env python3
      2 from utils.args import get_arguments, test_args
      3 from utils.read_file import read_ledger
      4 from utils.register import print_register
      5 from utils.sort import sort_entries
      6 from utils.balance import print_balance
      7 from utils.acc_regex import filter_accounts
      8 
      9 def main():
     10     args = get_arguments()
     11     test_args(args)
     12 
     13     if args.files:
     14         result = []
     15         for file in args.files:
     16             result += read_ledger(file)
     17 
     18     if len(args.verb) > 1:
     19         result = filter_accounts(args.verb[1:], result)
     20 
     21     if args.sort:
     22         sort_entries(result, args.sort)
     23 
     24     if args.verb[0] == 'print':
     25         for ent in result:
     26             print(ent)
     27 
     28     elif args.verb[0] in ['register', 'reg', 'r']:
     29         print_register(result)
     30 
     31     elif args.verb[0] in ['balance', 'bal', 'b']:
     32         print_balance(result)
     33 
     34 
     35 if __name__ == '__main__':
     36     main()