def show_history(only_transactions=True, limit=20, offset=0): checkbook = mf.get_checkbook() start = len(checkbook) - offset if limit is None: end = 0 else: end = start - limit if not only_transactions: to_print = checkbook[end:start] to_print.reverse() else: to_print = [ entry for entry in checkbook if entry["category"] == "transaction" ] to_print = to_print[end:start] to_print.reverse() if only_transactions: headers_list = ["ID", "Type", "Date", "Amount", "Balance"] else: headers_list = [ "ID", "Type", "Date", "Related Entries", "Amount", "Balance" ] for index, entry in enumerate(to_print): to_print[index] = printable_entry(entry, only_transactions=only_transactions) print(tabulate(to_print, headers=headers_list))
def checkbook_init(): if os.path.exists(log_file): if mf.get_checkbook() == []: mf.deposit(100, id_number=0) return else: open(log_file, "x") mf.deposit(100, id_number=0) return
def id_input(): checkbook = mf.get_checkbook() id_to_mod = input("ID number?") while not id_to_mod.isnumeric() or int(id_to_mod) >= len( checkbook) or checkbook[int( id_to_mod)]["category"] != "transaction": print("Invalid ID: " + id_to_mod + "\n") id_to_mod = input("ID number?") id_to_mod = int(id_to_mod) return id_to_mod