def graph(input_filename=None, output_filename=None): document = loadf(input_filename) flat_accounts = flatten_accounts(document.accounts) edges = construct_graph(document.events, flat_accounts) with output_stream(output_filename) as stream: print_graph(edges, stream)
def print_earnings_util(input_filename=None, output_filename=None): input_filename = argv[1] if len(argv) >= 2 else None document = loadf(input_filename) earnings = collect_earnings(document.events) with output_stream(output_filename) as out: print_earnings(document.accounts[2], earnings, out)
def extract(from_date_str, to_date_str, input_filename=None, output_filename=None): from_date = datetime.strptime(from_date_str, DATE_FORMAT).date() to_date = datetime.strptime(to_date_str, DATE_FORMAT).date() if from_date > to_date: raise ValueError("from_date > to_date") document = loadf(input_filename) inject_balances(document, from_date) drop_extra_events(document, from_date, to_date) document.begin = from_date document.end = to_date dumpf(output_filename, document)
def missing_accounts(*input_filenames): input_filenames = set(input_filenames) documents = ((filename, loadf(filename)) for filename in input_filenames) flat_accounts = dict((filename, flatten_accounts(document.accounts)) for (filename, document) in documents) all_accounts = dict() map(all_accounts.update, flat_accounts.itervalues()) havity = defaultdict(set) for account_num, account in all_accounts.iteritems(): for filename, accounts in flat_accounts.iteritems(): if account_num in accounts: havity[account_num].add(filename) for account_num, filenames in havity.iteritems(): fmt_filenames = " ".join(filenames) if filenames == input_filenames: if not ONLY: print "{account_num}: ALL {fmt_filenames}".format(**locals()) else: print "{account_num}: ONLY {fmt_filenames}".format(**locals())
def renumber(input_filename=None, output_filename=None): document = loadf(input_filename) sort_accounts(document.accounts) sort_events(document.events) renumber_events(document.events) dumpf(output_filename, document)
def merge_files(output_filename, *input_filenames): documents = (loadf(filename) for filename in input_filenames) merged = merge(*documents) dumpf(output_filename, merged)
def move_entries_util(from_account_num, to_account_num, input_filename=None, output_filename=None): from_account_num = int(from_account_num) to_account_num = int(to_account_num) document = loadf(input_filename) move_entries(document.events, from_account_num, to_account_num) dumpf(output_filename, document)
def indent(input_filename=None, output_filename=None): document = loadf(input_filename) dumpf(output_filename, document, pretty_print=True)
def main(): from sys import argv input_filename = argv[1] if len(argv) >= 2 else None document = loadf(input_filename) print_accounts(document.accounts)