mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-17 19:53:53 +02:00
fix: Make examples work
This commit is contained in:
@@ -32,16 +32,22 @@ def fetch_reports(priv_key: str) -> int:
|
||||
|
||||
# Step 1: construct a key object and get its location reports
|
||||
key = KeyPair.from_b64(priv_key)
|
||||
reports = acc.fetch_last_reports(key)
|
||||
location = acc.fetch_location(key)
|
||||
|
||||
# Step 2: print the reports!
|
||||
for report in sorted(reports):
|
||||
print(report)
|
||||
# Step 2: print it!
|
||||
print("Last known location:")
|
||||
print(f" - {location}")
|
||||
|
||||
# We can save the report to a file if we want
|
||||
report.to_json("last_report.json")
|
||||
# Step 3 (optional): We can save the location report to a file if we want.
|
||||
# BUT WATCH OUT! This file will contain the tag's private key!
|
||||
if location is not None:
|
||||
location.to_json("last_report.json")
|
||||
|
||||
# Step 3: Make sure to save account state when you're done!
|
||||
# To load it later:
|
||||
# loc = LocationReport.from_json("last_report.json")
|
||||
|
||||
# Step 4: Make sure to save account state when you're done!
|
||||
# Otherwise you have to log in again...
|
||||
acc.to_json(STORE_PATH)
|
||||
|
||||
return 0
|
||||
|
||||
@@ -34,18 +34,24 @@ async def fetch_reports(priv_key: str) -> int:
|
||||
|
||||
# Step 1: construct a key object and get its location reports
|
||||
key = KeyPair.from_b64(priv_key)
|
||||
reports = await acc.fetch_last_reports(key)
|
||||
location = await acc.fetch_location(key)
|
||||
|
||||
# Step 2: print the reports!
|
||||
for report in sorted(reports):
|
||||
print(report)
|
||||
# Step 2: print it!
|
||||
print("Last known location:")
|
||||
print(f" - {location}")
|
||||
|
||||
# We can save the report to a file if we want
|
||||
report.to_json("last_report.json")
|
||||
# Step 3 (optional): We can save the location report to a file if we want.
|
||||
# BUT WATCH OUT! This file will contain the tag's private key!
|
||||
if location is not None:
|
||||
location.to_json("last_report.json")
|
||||
|
||||
# To load it later:
|
||||
# loc = LocationReport.from_json("last_report.json")
|
||||
finally:
|
||||
await acc.close()
|
||||
|
||||
# Make sure to save account state when you're done!
|
||||
# Otherwise you have to log in again...
|
||||
acc.to_json(STORE_PATH)
|
||||
|
||||
return 0
|
||||
|
||||
@@ -31,34 +31,32 @@ ANISETTE_LIBS_PATH = "ani_libs.bin"
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
def main(plist_path: Path, alignment_plist_path: Path | None) -> int:
|
||||
def main(airtag_path: Path) -> int:
|
||||
# Step 0: create an accessory key generator
|
||||
airtag = FindMyAccessory.from_plist(plist_path, alignment_plist_path)
|
||||
airtag = FindMyAccessory.from_json(airtag_path)
|
||||
|
||||
# Step 1: log into an Apple account
|
||||
print("Logging into account")
|
||||
acc = get_account_sync(STORE_PATH, ANISETTE_SERVER, ANISETTE_LIBS_PATH)
|
||||
|
||||
# step 2: fetch reports!
|
||||
print("Fetching reports")
|
||||
reports = acc.fetch_last_reports(airtag)
|
||||
print("Fetching location")
|
||||
location = acc.fetch_location(airtag)
|
||||
|
||||
# step 3: print 'em
|
||||
print()
|
||||
print("Location reports:")
|
||||
for report in sorted(reports):
|
||||
print(f" - {report}")
|
||||
print("Last known location:")
|
||||
print(f" - {location}")
|
||||
|
||||
# step 4: save current account state to disk
|
||||
acc.to_json(STORE_PATH)
|
||||
airtag.to_json(airtag_path)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("plist_path", type=Path)
|
||||
parser.add_argument("--alignment_plist_path", default=None, type=Path)
|
||||
parser.add_argument("airtag_path", type=Path)
|
||||
args = parser.parse_args()
|
||||
|
||||
sys.exit(main(args.plist_path, args.alignment_plist_path))
|
||||
sys.exit(main(args.airtag_path))
|
||||
|
||||
@@ -1126,6 +1126,12 @@ class AppleAccount(BaseAppleAccount):
|
||||
coro = self._asyncacc.fetch_location_history(keys)
|
||||
return self._evt_loop.run_until_complete(coro)
|
||||
|
||||
@overload
|
||||
def fetch_location(
|
||||
self,
|
||||
keys: HasHashedPublicKey,
|
||||
) -> LocationReport | None: ...
|
||||
|
||||
@overload
|
||||
def fetch_location(
|
||||
self,
|
||||
|
||||
@@ -75,6 +75,7 @@ ignore = [
|
||||
"S101", # use of "assert"
|
||||
"D", # documentation
|
||||
"INP001", # namespacing
|
||||
"ERA001", # commented out code
|
||||
]
|
||||
"scripts/*" = [
|
||||
"T201", # use of "print"
|
||||
|
||||
Reference in New Issue
Block a user