fix: Make examples work

This commit is contained in:
Mike A.
2025-09-06 21:40:08 +02:00
parent 05ea2c9a74
commit 48007752af
5 changed files with 41 additions and 24 deletions

View File

@@ -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