findmy.reports.account ====================== .. py:module:: findmy.reports.account .. autoapi-nested-parse:: Module containing most of the code necessary to interact with an Apple account. Classes ------- .. autoapisummary:: findmy.reports.account.BaseAppleAccount findmy.reports.account.AsyncAppleAccount findmy.reports.account.AppleAccount Functions --------- .. autoapisummary:: findmy.reports.account.require_login_state Module Contents --------------- .. py:function:: require_login_state(*states: findmy.reports.state.LoginState) -> Callable[[_F], _F] Enforce a login state as precondition for a method. .. py:class:: BaseAppleAccount(loop: asyncio.AbstractEventLoop | None = None) Bases: :py:obj:`findmy.util.closable.Closable`, :py:obj:`abc.ABC` Base class for an Apple account. .. py:property:: login_state :type: findmy.reports.state.LoginState :abstractmethod: The current login state of the account. .. py:property:: account_name :type: str | None :abstractmethod: The name of the account as reported by Apple. This is usually an e-mail address. May be None in some cases, such as when not logged in. .. py:property:: first_name :type: str | None :abstractmethod: First name of the account holder as reported by Apple. May be None in some cases, such as when not logged in. .. py:property:: last_name :type: str | None :abstractmethod: Last name of the account holder as reported by Apple. May be None in some cases, such as when not logged in. .. py:method:: export() -> dict :abstractmethod: Export a representation of the current state of the account as a dictionary. The output of this method is guaranteed to be JSON-serializable, and passing the return value of this function as an argument to `BaseAppleAccount.restore` will always result in an exact copy of the internal state as it was when exported. This method is especially useful to avoid having to keep going through the login flow. .. py:method:: restore(data: dict) -> None :abstractmethod: Restore a previous export of the internal state of the account. See `BaseAppleAccount.export` for more information. .. py:method:: login(username: str, password: str) -> findmy.util.types.MaybeCoro[findmy.reports.state.LoginState] :abstractmethod: Log in to an Apple account using a username and password. .. py:method:: get_2fa_methods() -> findmy.util.types.MaybeCoro[Sequence[findmy.reports.twofactor.BaseSecondFactorMethod]] :abstractmethod: Get a list of 2FA methods that can be used as a secondary challenge. Currently, only SMS-based 2FA methods are supported. .. py:method:: sms_2fa_request(phone_number_id: int) -> findmy.util.types.MaybeCoro[None] :abstractmethod: Request a 2FA code to be sent to a specific phone number ID. Consider using `BaseSecondFactorMethod.request` instead. .. py:method:: sms_2fa_submit(phone_number_id: int, code: str) -> findmy.util.types.MaybeCoro[findmy.reports.state.LoginState] :abstractmethod: Submit a 2FA code that was sent to a specific phone number ID. Consider using `BaseSecondFactorMethod.submit` instead. .. py:method:: td_2fa_request() -> findmy.util.types.MaybeCoro[None] :abstractmethod: Request a 2FA code to be sent to a trusted device. Consider using `BaseSecondFactorMethod.request` instead. .. py:method:: td_2fa_submit(code: str) -> findmy.util.types.MaybeCoro[findmy.reports.state.LoginState] :abstractmethod: Submit a 2FA code that was sent to a trusted device. Consider using `BaseSecondFactorMethod.submit` instead. .. py:method:: fetch_reports(keys: findmy.keys.HasHashedPublicKey, date_from: datetime.datetime, date_to: datetime.datetime | None) -> findmy.util.types.MaybeCoro[list[findmy.reports.reports.LocationReport]] fetch_reports(keys: Sequence[findmy.keys.HasHashedPublicKey], date_from: datetime.datetime, date_to: datetime.datetime | None) -> findmy.util.types.MaybeCoro[dict[findmy.keys.HasHashedPublicKey, list[findmy.reports.reports.LocationReport]]] fetch_reports(keys: findmy.accessory.RollingKeyPairSource, date_from: datetime.datetime, date_to: datetime.datetime | None) -> findmy.util.types.MaybeCoro[list[findmy.reports.reports.LocationReport]] :abstractmethod: Fetch location reports for `HasHashedPublicKey`s between `date_from` and `date_end`. Returns a dictionary mapping `HasHashedPublicKey`s to a list of their location reports. .. py:method:: fetch_last_reports(keys: findmy.keys.HasHashedPublicKey, hours: int = 7 * 24) -> findmy.util.types.MaybeCoro[list[findmy.reports.reports.LocationReport]] fetch_last_reports(keys: Sequence[findmy.keys.HasHashedPublicKey], hours: int = 7 * 24) -> findmy.util.types.MaybeCoro[dict[findmy.keys.HasHashedPublicKey, list[findmy.reports.reports.LocationReport]]] fetch_last_reports(keys: findmy.accessory.RollingKeyPairSource, hours: int = 7 * 24) -> findmy.util.types.MaybeCoro[list[findmy.reports.reports.LocationReport]] :abstractmethod: Fetch location reports for a sequence of `HasHashedPublicKey`s for the last `hours` hours. Utility method as an alternative to using `BaseAppleAccount.fetch_reports` directly. .. py:method:: get_anisette_headers(with_client_info: bool = False, serial: str = '0') -> findmy.util.types.MaybeCoro[dict[str, str]] :abstractmethod: Retrieve a complete dictionary of Anisette headers. Utility method for `AnisetteProvider.get_headers` using this account's user and device ID. .. py:class:: AsyncAppleAccount(anisette: findmy.reports.anisette.BaseAnisetteProvider, user_id: str | None = None, device_id: str | None = None) Bases: :py:obj:`BaseAppleAccount` An async implementation of `BaseAppleAccount`. .. py:property:: login_state :type: findmy.reports.state.LoginState See `BaseAppleAccount.login_state`. .. py:property:: account_name :type: str | None See `BaseAppleAccount.account_name`. .. py:property:: first_name :type: str | None See `BaseAppleAccount.first_name`. .. py:property:: last_name :type: str | None See `BaseAppleAccount.last_name`. .. py:method:: export() -> dict See `BaseAppleAccount.export`. .. py:method:: restore(data: dict) -> None See `BaseAppleAccount.restore`. .. py:method:: close() -> None :async: Close any sessions or other resources in use by this object. Should be called when the object will no longer be used. .. py:method:: login(username: str, password: str) -> findmy.reports.state.LoginState :async: See `BaseAppleAccount.login`. .. py:method:: get_2fa_methods() -> Sequence[findmy.reports.twofactor.AsyncSecondFactorMethod] :async: See `BaseAppleAccount.get_2fa_methods`. .. py:method:: sms_2fa_request(phone_number_id: int) -> None :async: See `BaseAppleAccount.sms_2fa_request`. .. py:method:: sms_2fa_submit(phone_number_id: int, code: str) -> findmy.reports.state.LoginState :async: See `BaseAppleAccount.sms_2fa_submit`. .. py:method:: td_2fa_request() -> None :async: See `BaseAppleAccount.td_2fa_request`. .. py:method:: td_2fa_submit(code: str) -> findmy.reports.state.LoginState :async: See `BaseAppleAccount.td_2fa_submit`. .. py:method:: fetch_raw_reports(start: int, end: int, ids: list[str]) -> dict[str, Any] :async: Make a request for location reports, returning raw data. .. py:method:: fetch_reports(keys: findmy.keys.HasHashedPublicKey, date_from: datetime.datetime, date_to: datetime.datetime | None) -> list[findmy.reports.reports.LocationReport] fetch_reports(keys: Sequence[findmy.keys.HasHashedPublicKey], date_from: datetime.datetime, date_to: datetime.datetime | None) -> dict[findmy.keys.HasHashedPublicKey, list[findmy.reports.reports.LocationReport]] fetch_reports(keys: findmy.accessory.RollingKeyPairSource, date_from: datetime.datetime, date_to: datetime.datetime | None) -> list[findmy.reports.reports.LocationReport] :async: See `BaseAppleAccount.fetch_reports`. .. py:method:: fetch_last_reports(keys: findmy.keys.HasHashedPublicKey, hours: int = 7 * 24) -> list[findmy.reports.reports.LocationReport] fetch_last_reports(keys: Sequence[findmy.keys.HasHashedPublicKey], hours: int = 7 * 24) -> dict[findmy.keys.HasHashedPublicKey, list[findmy.reports.reports.LocationReport]] fetch_last_reports(keys: findmy.accessory.RollingKeyPairSource, hours: int = 7 * 24) -> list[findmy.reports.reports.LocationReport] :async: See `BaseAppleAccount.fetch_last_reports`. .. py:method:: get_anisette_headers(with_client_info: bool = False, serial: str = '0') -> dict[str, str] :async: See `BaseAppleAccount.get_anisette_headers`. .. py:class:: AppleAccount(anisette: findmy.reports.anisette.BaseAnisetteProvider, user_id: str | None = None, device_id: str | None = None) Bases: :py:obj:`BaseAppleAccount` A sync implementation of `BaseappleAccount`. Uses `AsyncappleAccount` internally. .. py:method:: close() -> None :async: See `AsyncAppleAccount.close`. .. py:property:: login_state :type: findmy.reports.state.LoginState See `AsyncAppleAccount.login_state`. .. py:property:: account_name :type: str | None See `AsyncAppleAccount.login_state`. .. py:property:: first_name :type: str | None See `AsyncAppleAccount.first_name`. .. py:property:: last_name :type: str | None See `AsyncAppleAccount.last_name`. .. py:method:: export() -> dict See `AsyncAppleAccount.export`. .. py:method:: restore(data: dict) -> None See `AsyncAppleAccount.restore`. .. py:method:: login(username: str, password: str) -> findmy.reports.state.LoginState See `AsyncAppleAccount.login`. .. py:method:: get_2fa_methods() -> Sequence[findmy.reports.twofactor.SyncSecondFactorMethod] See `AsyncAppleAccount.get_2fa_methods`. .. py:method:: sms_2fa_request(phone_number_id: int) -> None See `AsyncAppleAccount.sms_2fa_request`. .. py:method:: sms_2fa_submit(phone_number_id: int, code: str) -> findmy.reports.state.LoginState See `AsyncAppleAccount.sms_2fa_submit`. .. py:method:: td_2fa_request() -> None See `AsyncAppleAccount.td_2fa_request`. .. py:method:: td_2fa_submit(code: str) -> findmy.reports.state.LoginState See `AsyncAppleAccount.td_2fa_submit`. .. py:method:: fetch_reports(keys: findmy.keys.HasHashedPublicKey, date_from: datetime.datetime, date_to: datetime.datetime | None) -> list[findmy.reports.reports.LocationReport] fetch_reports(keys: Sequence[findmy.keys.HasHashedPublicKey], date_from: datetime.datetime, date_to: datetime.datetime | None) -> dict[findmy.keys.HasHashedPublicKey, list[findmy.reports.reports.LocationReport]] fetch_reports(keys: findmy.accessory.RollingKeyPairSource, date_from: datetime.datetime, date_to: datetime.datetime | None) -> list[findmy.reports.reports.LocationReport] See `AsyncAppleAccount.fetch_reports`. .. py:method:: fetch_last_reports(keys: findmy.keys.HasHashedPublicKey, hours: int = 7 * 24) -> list[findmy.reports.reports.LocationReport] fetch_last_reports(keys: Sequence[findmy.keys.HasHashedPublicKey], hours: int = 7 * 24) -> dict[findmy.keys.HasHashedPublicKey, list[findmy.reports.reports.LocationReport]] fetch_last_reports(keys: findmy.accessory.RollingKeyPairSource, hours: int = 7 * 24) -> list[findmy.reports.reports.LocationReport] See `AsyncAppleAccount.fetch_last_reports`. .. py:method:: get_anisette_headers(with_client_info: bool = False, serial: str = '0') -> dict[str, str] See `AsyncAppleAccount.get_anisette_headers`.