Source code for fatsecret.resources._generated.weight

# AUTO-GENERATED by scripts/oas-sync emit-resource Weight Diary. Do not edit by hand.
"""Resource wrapper for the OAS ``Weight Diary`` tag (generated)."""

from __future__ import annotations

from typing import Any, Optional

from .._base import BaseResource

from ...models._generated.weight_diary import Day


[docs] class WeightResource(BaseResource): """Resource methods for the OAS `Weight Diary` tag (generated)."""
[docs] def get_month_v1( self, date: Optional[int] = None, ) -> list[Day]: """Returns the recorded weights for a user for the month specified. Use this call to display a user's weight chart or log of weight changes for a nominated month. The day elements returned are those where the user entered or updated their weight for the specified month. Days with no recorded weight are not included. :param date: Number of days since January 1, 1970 (default value is the current day) :return: List of :class:`Day` instances. Notes: weights.get_month (v1). DEPRECATED upstream. Premier-only. """ params: dict[str, Any] = {"method": "weights.get_month"} self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ], ) payload = self._client._call(params) raw = self._client._unwrap(payload, "month", list_key="day") return [Day.model_validate(r) for r in raw]
[docs] def get_month_v2( self, date: Optional[int] = None, ) -> list[Day]: """Returns the recorded weights for a user for the month specified. Use this call to display a user's weight chart or log of weight changes for a nominated month. The day elements returned are those where the user entered or updated their weight for the specified month. Days with no recorded weight are not included. :param date: Number of days since January 1, 1970 (default value is the current day) :return: List of :class:`Day` instances. Notes: weights.get_month (v2). Premier-only. """ params: dict[str, Any] = {"method": "weights.get_month.v2"} self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ], ) payload = self._client._call(params) raw = self._client._unwrap(payload, "month", list_key="day") return [Day.model_validate(r) for r in raw]
[docs] def update_v1( self, current_weight_kg: float, date: Optional[int] = None, weight_type: Optional[str] = None, height_type: Optional[str] = None, goal_weight_kg: Optional[float] = None, current_height_cm: Optional[float] = None, comment: Optional[str] = None, ) -> bool: """Records a user's weight for a nominated date. First time weigh-ins require the goal_weight_kg and current_height_cm parameters. Please note as per the API Terms of Use that it is your responsibility to ensure that the information generated by using the API is not be interpreted as a substitute for medical physician consultation, evaluation, or treatment. :param current_weight_kg: Current weight of the user in kilograms :param date: Number of days since January 1, 1970 (default value is the current day) :param weight_type: Weight measurement type for this user profile. Valid types are "kg" and "lb" (default value is "kg") :param height_type: Height measurement type for this user profile. Valid types are "cm" and "inch" (default value is "cm") :param goal_weight_kg: User's goal weight in kilograms :param current_height_cm: Current height of the user in centimetres. This is required for the first weigh-in. You can only set this for the first time :param comment: A comment for this weigh-in Notes: weight.update (v1). Premier-only. """ params: dict[str, Any] = {"method": "weight.update"} params["current_weight_kg"] = current_weight_kg self._client._set_optional( params, [ ("date", None if date is None else self._client.unix_time_v2(date)), ("weight_type", weight_type), ("height_type", height_type), ("goal_weight_kg", goal_weight_kg), ("current_height_cm", current_height_cm), ("comment", comment), ], ) payload = self._client._call(params, method="POST") return self._client._mutator_success(payload)
__all__ = ["WeightResource"]