Ejemplo n.º 1
0
def account(request, account_id):
    app_name = request.build_absolute_uri().split('.')[0][8:]
    client = Monzo(os.environ.get('MONZO_ACCESS_TOKEN'))
    try:
        settings = Settings.objects.filter()[0]
        settings.last_used_account = account_id
        settings.save()
    except:
        Settings.objects.create(last_used_account=account_id)

    try:
        webhooks = client.get_webhooks(account_id)['webhooks']
        print(webhooks)
        webhook_active = bool(webhooks)

        accounts = client.get_accounts()['accounts']
        print(accounts)

        tags = Tag.objects.all()

    except (BadRequestError, UnauthorizedError):
        return render(request, 'invalid-token.html', {'app_name': app_name})

    context = {
        'app_name': app_name,
        'accounts': accounts,
        'account_id': account_id,
        'tags': tags,
        'webhook_active': webhook_active,
        'strftime_codes': strftime_code
    }
    return render(request, 'account.html', context)
Ejemplo n.º 2
0
def activate_webhook(request, account_id):

    webhook, created = Webhook.objects.get_or_create(id=account_id)
    webhook.enabled = True
    webhook.save()

    client = Monzo(os.environ.get('MONZO_ACCESS_TOKEN'))
    webhook_url = request.build_absolute_uri('webhook/' + account_id)
    client.register_webhook(webhook_url=webhook_url, account_id=account_id)

    print(client.get_webhooks(account_id))

    return redirect('index')