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)
def index(request): app_name = request.build_absolute_uri().split('.')[0][8:] client = Monzo(os.environ.get('MONZO_ACCESS_TOKEN')) try: account = client.get_first_account() if account['closed']: account_id = client.get_accounts()['accounts'][1]['id'] else: account_id = account['id'] except (BadRequestError, UnauthorizedError): return render(request, 'invalid-token.html', {'app_name': app_name}) return redirect('account', account_id)