import pyteamsnap


def get_teamsnap_client(request):
    request.user.socialaccount_set.filter(provider="teamsnap").first()
    current_teamsnap_user = request.user.socialaccount_set.filter(
        provider="teamsnap"
    ).first()

    ts_token = (
        current_teamsnap_user.socialtoken_set.order_by("-expires_at").first().token
    )

    return pyteamsnap.api.TeamSnap(token=ts_token)
