예제 #1
0
def complete_oura(request):

    if request.GET.get("state") != os.getenv("SECRET_KEY") or request.GET.get(
            "error"):
        return redirect("info")

    res = requests.post(
        "https://api.ouraring.com/oauth/token",
        data={
            "grant_type":
            "authorization_code",
            "code":
            request.GET.get("code"),
            "redirect_uri":
            request.build_absolute_uri(reverse("import_data:complete-oura")),
            "client_id":
            os.getenv("OURA_CLIENT_ID"),
            "client_secret":
            os.getenv("OURA_CLIENT_SECRET"),
        },
    ).json()

    OuraMember.objects.update_or_create(
        member=request.user.openhumansmember,
        defaults={
            "access_token":
            res["access_token"],
            "refresh_token":
            res["refresh_token"],
            "expiration_time":
            arrow.utcnow().shift(seconds=res["expires_in"]).datetime,
        },
    )
    update_oura_data.delay(request.user.openhumansmember.oura_user.id)
    return redirect("/")
예제 #2
0
    def handle(self, *args, **options):
        # cheat to wake up sleeping worker
        requests.get("https://oh-oura-connect.herokuapp.com/")

        oura_users = OuraMember.objects.all()
        for o in oura_users:
            update_oura_data.delay(o.id)
            print("submitted oura update for {}".format(o.id))
            time.sleep(2)

        fitbit_users = FitbitMember.objects.all()
        for f in fitbit_users:
            update_fitbit_data.delay(f.id)
            print("submitted fitbit update for {}".format(f.id))
            time.sleep(2)
예제 #3
0
def update_oura(request):
    if request.method == "POST":
        update_oura_data.delay(request.user.openhumansmember.oura_user.id)
        return redirect("/")