コード例 #1
0
def init():
    global configuration, api_client, accounts_api, categories_api, transactions_api, payees_api
    utils.log_debug('api_client.init')
    configuration = ynab_api.configuration.Configuration()
    if not settings.get('api_token'):
        afy.install.install()
        assert settings.get('api_token')
    configuration.api_key['Authorization'] = settings.get('api_token')
    configuration.api_key_prefix['Authorization'] = 'Bearer'

    api_client = ynab_api.api_client.ApiClient(configuration)

    accounts_api = ynab_api.AccountsApi(api_client)
    categories_api = ynab_api.CategoriesApi(api_client)
    transactions_api = ynab_api.TransactionsApi(api_client)
    payees_api = ynab_api.PayeesApi(api_client)

    global initialized
    initialized = True
コード例 #2
0
ファイル: install.py プロジェクト: jodfie/assistantforynab
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()
コード例 #3
0
ファイル: install.py プロジェクト: jodfie/assistantforynab
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()