Coverage for /home/kale/hacking/hobbies/two_cents/two_cents/cli : 73%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python3
Maintain a budget that updates every day.
Usage: two_cents [-d] [-D] [-I] [-h] [-v] two_cents add-bank <name> [-u <command>] [-p <command>] two_cents add-budget <name> [-b <dollars>] [-a <dollars-per-time>] two_cents describe-budgets [-e] two_cents download-payments [-I] two_cents reassign-payment <payment-id> <budget> two_cents show-allowance [<budgets>...] two_cents show-payments [<budget>] two_cents suggest-allowance [<budgets>...] two_cents transfer-allowance <dollars-per-time> <budget-from> <budget-to> two_cents transfer-money <dollars> <budget-from> <budget-to>
Options: -d, --download Force new transactions to be downloaded from the bank. Downloading new transactions is the default behavior, so the purpose of this flag is to allow the --no-download flag to be overridden.
-D, --no-download Don't download new transactions from the bank. This can be a slow step, so you may want to skip it if you know nothing new has happened.
-I, --no-interaction Don't use stdin to prompt for passwords. If a password command is found in the database, use that. Otherwise print an error message and exit.
-u, --username-cmd <command> When adding a new bank, use this option to specify a command that can be used to get your username. You will be prompted for one if this option isn't specified.
-p, --password-cmd <command> When adding a new bank, use this option to specify a command that can be used to get your password. You will be prompted for one if this option isn't specified.
-b, --initial-balance <dollars> When adding a new budget, specify how much money should start off in the budget.
-a, --initial-allowance <dollars-per-time> When adding a new budget, specify how quickly money should accumulate in that budget.
-e, --edit Indicate that you want to create or update a description of your budgeting scheme.
-h, --help Print out this message.
-v, --version Print the version number of the installed two_cents executable. """
print('two_cents 0.0') raise SystemExit
import os db_path = os.path.join(dirs.user_config_dir, 'budgets.db')
session, scraper_key=args['<name>'], username_cmd=args['--username-cmd'], password_cmd=args['--password-cmd'], ) session, name=args['<name>'], initial_balance=args['--initial-balance'], initial_allowance=args['--initial-allowance'], ) describe_budgets( edit=args['--edit'], ) download_payments( session, interactive=not args['--no-interaction'], ) session, args['<payment-id>'], args['<budget>'], ) show_allowance( session, *args['<budgets>'] ) session, args['<budget>'], ) suggest_allowance( session, *args['<budgets>'] ) session, args['<dollars>'], args['<budget-from>'], args['<budget-to>'], ) else: session, download=args['--download'] or not args['--no-download'], interactive=not args['--no-interaction'], ) except KeyboardInterrupt: print()
Enter username and password commands. You don't need to provide either command, but if you don't you'll have to provide the missing fields every time you download financial data from this bank.""")
Enter a username command. If no command is given, you'll be prompted for a username every time you download financial data from this bank.""")
Enter a password command. If no command is given, you'll be prompted for a password every time you download financial data from this bank.""")
import os import subprocess
description_path = os.path.join(dirs.user_config_dir, 'description.txt')
if edit or not os.path.exists(description_path): editor = os.environ.get('EDITOR', 'vi') subprocess.call((editor, description_path)) else: with open(description_path) as file: print(file.read().strip())
two_cents.download_payments( session, get_username_prompter(interactive), get_password_prompter(interactive), )
with print_table('lr') as table: for budget in two_cents.get_budgets(session, *budgets): table.add_row([ budget.name.title(), budget.pretty_allowance, ])
# Populate a table with suggested allowances for each budget, then display # that table.
with print_table('lr') as table: for budget in two_cents.get_budgets(session, *budgets): table.add_row([ budget.name.title(), "{}/mo".format(two_cents.format_dollars( two_cents.suggest_allowance(session, budget))), ])
two_cents.parse_dollars(dollars), two_cents.get_budget(session, budget_from), two_cents.get_budget(session, budget_to))
print("Downloading recent transactions...") download_payments(session, interactive)
import builtins return builtins.print(*args, **kwargs)
if password: import getpass return getpass.getpass(message) else: return input(message)
# Handle the payments using a simple state machine. This architecture # facilitates commands like 'skip all' and 'ignore all'.
else:
# Prompt the user for an assignment.
# See if the user wants to skip assigning one or more payments # and come back to them later.
self.handle = self.null_handler break
# See if the user wants to ignore one or more payments. These # payments will be permanently excluded from the budget.
payment.ignore() self.handle = self.ignore_handler break
# Attempt to assign the payment to the specified budgets. If # the input can't be parsed, print an error and ask again.
except two_cents.UserError as error: print(error.message)
payment.ignore()
pass
results = [x for x in self.commands if x.startswith(prefix)] try: return results[index] except IndexError: return None
""" Print a line briefly summarizing each budget. """
# I had to hack table.right_padding_width a little to format the recovery # time the way I wanted. Basically, I use table.right_padding_width to add # manual padding, then I remove the padding once the table is complete.
budget.name.title() + ' ' * table.right_padding_width, budget.pretty_balance + ' ', '' if budget.recovery_time <= 0 else '({} {})'.format(budget.recovery_time, 'day' if budget.recovery_time == 1 else 'days') ])
else: payment.description, width=79, initial_indent=indent+' ', subsequent_indent=indent+' ')
def username_prompter(bank, error_message): if error_message: print(error_message) if not interactive: raise SystemExit return prompt("Username for {}: ".format(bank)) return username_prompter
def password_prompter(bank, error_message): if error_message: print(error_message) if not interactive: raise SystemExit return prompt("Password for {}: ".format(bank), password=True) return password_prompter
|