mirror of
https://github.com/malmeloo/FindMy.py.git
synced 2026-04-18 00:53:56 +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
|
# Step 1: construct a key object and get its location reports
|
||||||
key = KeyPair.from_b64(priv_key)
|
key = KeyPair.from_b64(priv_key)
|
||||||
reports = acc.fetch_last_reports(key)
|
location = acc.fetch_location(key)
|
||||||
|
|
||||||
# Step 2: print the reports!
|
# Step 2: print it!
|
||||||
for report in sorted(reports):
|
print("Last known location:")
|
||||||
print(report)
|
print(f" - {location}")
|
||||||
|
|
||||||
# We can save the report to a file if we want
|
# Step 3 (optional): We can save the location report to a file if we want.
|
||||||
report.to_json("last_report.json")
|
# 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)
|
acc.to_json(STORE_PATH)
|
||||||
|
|
||||||
return 0
|
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
|
# Step 1: construct a key object and get its location reports
|
||||||
key = KeyPair.from_b64(priv_key)
|
key = KeyPair.from_b64(priv_key)
|
||||||
reports = await acc.fetch_last_reports(key)
|
location = await acc.fetch_location(key)
|
||||||
|
|
||||||
# Step 2: print the reports!
|
# Step 2: print it!
|
||||||
for report in sorted(reports):
|
print("Last known location:")
|
||||||
print(report)
|
print(f" - {location}")
|
||||||
|
|
||||||
# We can save the report to a file if we want
|
# Step 3 (optional): We can save the location report to a file if we want.
|
||||||
report.to_json("last_report.json")
|
# 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:
|
finally:
|
||||||
await acc.close()
|
await acc.close()
|
||||||
|
|
||||||
# Make sure to save account state when you're done!
|
# Make sure to save account state when you're done!
|
||||||
|
# Otherwise you have to log in again...
|
||||||
acc.to_json(STORE_PATH)
|
acc.to_json(STORE_PATH)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -31,34 +31,32 @@ ANISETTE_LIBS_PATH = "ani_libs.bin"
|
|||||||
logging.basicConfig(level=logging.INFO)
|
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
|
# 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
|
# Step 1: log into an Apple account
|
||||||
print("Logging into account")
|
print("Logging into account")
|
||||||
acc = get_account_sync(STORE_PATH, ANISETTE_SERVER, ANISETTE_LIBS_PATH)
|
acc = get_account_sync(STORE_PATH, ANISETTE_SERVER, ANISETTE_LIBS_PATH)
|
||||||
|
|
||||||
# step 2: fetch reports!
|
# step 2: fetch reports!
|
||||||
print("Fetching reports")
|
print("Fetching location")
|
||||||
reports = acc.fetch_last_reports(airtag)
|
location = acc.fetch_location(airtag)
|
||||||
|
|
||||||
# step 3: print 'em
|
# step 3: print 'em
|
||||||
print()
|
print("Last known location:")
|
||||||
print("Location reports:")
|
print(f" - {location}")
|
||||||
for report in sorted(reports):
|
|
||||||
print(f" - {report}")
|
|
||||||
|
|
||||||
# step 4: save current account state to disk
|
# step 4: save current account state to disk
|
||||||
acc.to_json(STORE_PATH)
|
acc.to_json(STORE_PATH)
|
||||||
|
airtag.to_json(airtag_path)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("plist_path", type=Path)
|
parser.add_argument("airtag_path", type=Path)
|
||||||
parser.add_argument("--alignment_plist_path", default=None, type=Path)
|
|
||||||
args = parser.parse_args()
|
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)
|
coro = self._asyncacc.fetch_location_history(keys)
|
||||||
return self._evt_loop.run_until_complete(coro)
|
return self._evt_loop.run_until_complete(coro)
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def fetch_location(
|
||||||
|
self,
|
||||||
|
keys: HasHashedPublicKey,
|
||||||
|
) -> LocationReport | None: ...
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def fetch_location(
|
def fetch_location(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ ignore = [
|
|||||||
"S101", # use of "assert"
|
"S101", # use of "assert"
|
||||||
"D", # documentation
|
"D", # documentation
|
||||||
"INP001", # namespacing
|
"INP001", # namespacing
|
||||||
|
"ERA001", # commented out code
|
||||||
]
|
]
|
||||||
"scripts/*" = [
|
"scripts/*" = [
|
||||||
"T201", # use of "print"
|
"T201", # use of "print"
|
||||||
|
|||||||
Reference in New Issue
Block a user