mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-18 02:54:01 +02:00
Cleanup examples
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
# ruff: noqa: T201, D103, S101
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from findmy import KeyPair
|
||||
from findmy.reports import (
|
||||
AppleAccount,
|
||||
LoginState,
|
||||
RemoteAnisetteProvider,
|
||||
keys,
|
||||
SmsSecondFactorMethod,
|
||||
)
|
||||
|
||||
@@ -15,7 +16,7 @@ ANISETTE_SERVER = "http://localhost:6969"
|
||||
|
||||
# Apple account details
|
||||
ACCOUNT_EMAIL = "test@test.com"
|
||||
ACCOUNT_PASS = "1234"
|
||||
ACCOUNT_PASS = ""
|
||||
|
||||
# Private base64-encoded key to look up
|
||||
KEY_PRIV = ""
|
||||
@@ -26,7 +27,7 @@ KEY_ADV = ""
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
def login(account: AppleAccount):
|
||||
def login(account: AppleAccount) -> None:
|
||||
state = account.login(ACCOUNT_EMAIL, ACCOUNT_PASS)
|
||||
|
||||
if state == LoginState.REQUIRE_2FA: # Account requires 2FA
|
||||
@@ -46,20 +47,19 @@ def login(account: AppleAccount):
|
||||
# This automatically finishes the post-2FA login flow
|
||||
method.submit(code)
|
||||
|
||||
return account
|
||||
|
||||
|
||||
def fetch_reports(lookup_key):
|
||||
def fetch_reports(lookup_key: KeyPair) -> None:
|
||||
anisette = RemoteAnisetteProvider(ANISETTE_SERVER)
|
||||
acc = AppleAccount(anisette)
|
||||
|
||||
# Save / restore account logic
|
||||
if os.path.isfile("account.json"):
|
||||
with open("account.json") as f:
|
||||
acc_store = Path("account.json")
|
||||
try:
|
||||
with acc_store.open() as f:
|
||||
acc.restore(json.load(f))
|
||||
else:
|
||||
except FileNotFoundError:
|
||||
login(acc)
|
||||
with open("account.json", "w+") as f:
|
||||
with acc_store.open("w+") as f:
|
||||
json.dump(acc.export(), f)
|
||||
|
||||
print(f"Logged in as: {acc.account_name} ({acc.first_name} {acc.last_name})")
|
||||
@@ -70,7 +70,7 @@ def fetch_reports(lookup_key):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
key = keys.KeyPair.from_b64(KEY_PRIV)
|
||||
key = KeyPair.from_b64(KEY_PRIV)
|
||||
if KEY_ADV: # verify that your adv key is correct :D
|
||||
assert key.adv_key_b64 == KEY_ADV
|
||||
|
||||
|
||||
Reference in New Issue
Block a user