-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
35 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 @@ | |
|
||
# Apple account details | ||
ACCOUNT_EMAIL = "[email protected]" | ||
ACCOUNT_PASS = "1234" | ||
ACCOUNT_PASS = "" | ||
|
||
# Private base64-encoded key to look up | ||
KEY_PRIV = "" | ||
|
@@ -26,7 +27,7 @@ | |
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
# ruff: noqa: T201, D103, S101 | ||
import asyncio | ||
import json | ||
import logging | ||
import os | ||
from pathlib import Path | ||
|
||
from findmy import KeyPair | ||
from findmy.reports import ( | ||
AsyncAppleAccount, | ||
LoginState, | ||
RemoteAnisetteProvider, | ||
SmsSecondFactorMethod, | ||
keys, | ||
) | ||
|
||
# URL to (public or local) anisette server | ||
ANISETTE_SERVER = "http://localhost:6969" | ||
|
||
# Apple account details | ||
ACCOUNT_EMAIL = "[email protected]" | ||
ACCOUNT_PASS = "1234" | ||
ACCOUNT_PASS = "" | ||
|
||
# Private base64-encoded key to look up | ||
KEY_PRIV = "" | ||
|
@@ -27,7 +28,7 @@ | |
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
async def login(account: AsyncAppleAccount): | ||
async def login(account: AsyncAppleAccount) -> None: | ||
state = await account.login(ACCOUNT_EMAIL, ACCOUNT_PASS) | ||
|
||
if state == LoginState.REQUIRE_2FA: # Account requires 2FA | ||
|
@@ -47,21 +48,19 @@ async def login(account: AsyncAppleAccount): | |
# This automatically finishes the post-2FA login flow | ||
await method.submit(code) | ||
|
||
return account | ||
|
||
|
||
async def fetch_reports(lookup_key): | ||
async def fetch_reports(lookup_key: KeyPair) -> None: | ||
anisette = RemoteAnisetteProvider(ANISETTE_SERVER) | ||
acc = AsyncAppleAccount(anisette) | ||
|
||
try: | ||
# 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: | ||
await 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})") | ||
|
@@ -75,7 +74,7 @@ async 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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters