Exemple #1
0
def do_delete():
    utils.log_debug('do_delete')
    for a in account_delete_queue.values():
        queue_delete_transactions(afy.Assistant.transactions.by_name(a.name))
    do_delete_transactions()
    do_delete_accounts()
    gui.quit()
Exemple #2
0
def add_unlinked_account(account_name, balance=0, account_type='credit'):
    utils.log_debug('add_unlinked_account', account_name, balance, account_type)
    gui_client.add_unlinked_account(account_name, balance, account_type)
    gui.quit()
    afy.Assistant.download_ynab(accounts=True)
    start = time.time()
    while time.time() - start < 30:  # TODO: generic retrier
        new_account = afy.Assistant.accounts.by_name(account_name)
        if new_account:
            return new_account
    assert False
Exemple #3
0
def enter_all_transactions(transactions):
    utils.log_debug('enter_all_transactions', len(transactions))
    load_gui()
    for t in transactions:
        utils.log_info(t)
        if len(t.subtransactions) > 5:
            utils.log_info(
                '''Skipping purchase with %s items for speed reasons during alpha test.
                   Feel free to remove this check.''' % len(t.subtransactions))
            continue
        try:
            enter_transaction(t)
        except BaseException:
            ' Likely because there were multiple search results '
            utils.log_exception()
            utils.log_error('Error on transaction', t)
            search = gui.get('transaction-search-input')
            search.clear()
    gui.quit()
Exemple #4
0
def do_gui():
    utils.log_debug('do_gui', gui_queue)
    if not gui_queue:
        return
    old_memos = []
    for mode, ts in gui_queue.items():
        utils.log_info('%s %s transactions via YNAB webapp' % (mode, len(ts)))
        utils.log_debug(mode, ts)
        for t in ts.values():  # TODO: can this be simplified?
            if len(t.subtransactions) <= 1:
                utils.log_debug('Warning: no good reason to update via gui with %s subtransaction(s)' %
                                len(t.subtransactions), t)
            # Ensures that we can find it in the gui
            old_memos.append(annotate_for_locating(t))
        rest_modes[mode](ts)
        for m, t in zip(old_memos, ts.values()):  # simplify out the .values? listy?
            t.memo = m
            add_adjustment_subtransaction(t)
        gui_client.enter_all_transactions(ts)
        utils.log_info(utils.separator)
    gui_queue.clear()
    gui.quit()
Exemple #5
0
def setup_ynab_budget_id():
    utils.log_info('Checking for selected budget')
    if settings.get('budget_id'):
        return
    utils.log_info('Selecting budget')
    url = 'https://app.youneedabudget.com/'
    driver = gui.driver()
    driver.get(url)
    utils.log_info('Log in if needed')
    while not re.search('youneedabudget.com/([^/]+)/', driver.current_url):
        time.sleep(.5)
    budget_selection_prompt = 'Press Enter when you have loaded the budget you want to use.'
    input(budget_selection_prompt)
    utils.log_debug(budget_selection_prompt)
    while not re.search('youneedabudget.com/([^/]+)/', driver.current_url):
        time.sleep(.5)
    settings.set(
        'budget_id',
        re.search('youneedabudget.com/([^/]+)/',
                  driver.current_url).groups()[0])
    utils.log_debug('settings.budget_id', settings.budget_id)
    assert settings.budget_id
    gui.quit()
Exemple #6
0
def setup_ynab_auth():
    utils.log_info('Checking for YNAB authentication')
    # TODO: make this use oauth instead of api tokens
    if settings.get('api_token'):
        return
    utils.log_info('Installing YNAB authentication')
    api_token_url = 'https://app.youneedabudget.com/settings/developer'
    d = gui.driver()
    d.get(api_token_url)
    utils.log_info('Log in if needed')
    new_token_button = gui.get_by_text('button', 'New Token')
    gui.click(new_token_button)
    utils.log_info(
        'Enter your password in the YNAB Web App, then click "Generate"')
    while 'New Personal Access Token' not in d.page_source:
        time.sleep(.5)
    api_token = re.search(
        'New Personal Access Token: <strong>([^<]*)</strong>',
        d.page_source).groups()[0]
    settings.set('api_token', api_token)
    utils.log_debug('settings.api_token', settings.api_token)
    assert settings.api_token
    gui.quit()