Skip to content

Commit 8d0e6a0

Browse files
committed
better naming
1 parent 14d00f2 commit 8d0e6a0

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

main.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,31 @@ def get_args():
4343

4444

4545
if __name__ == "__main__":
46-
args = get_args()
47-
beamers = fetch_devices(args.startpoint, headers=args.headers)
48-
if args.verbose:
49-
print("Beamers:", len(beamers))
50-
devices = {}
51-
for device in beamers:
52-
private_key_bytes = bytes(device["privateKey"]["data"])
46+
command_args = get_args()
47+
48+
beamer_devices = fetch_devices(
49+
command_args.startpoint, headers=command_args.headers
50+
)
51+
if command_args.verbose:
52+
print("Beamers:", len(beamer_devices))
53+
54+
device_mapping = {}
55+
for device in beamer_devices:
56+
privateKeyBytes = bytes(device["privateKey"]["data"])
5357
del device["privateKey"]
54-
device["privateKeyInt"] = bytes_to_int(private_key_bytes)
55-
public_hash_b64 = b64_ascii(get_hashed_public_key(private_key_bytes))
56-
devices[public_hash_b64] = device
57-
result = apple_fetch(args.key, list(devices.keys()))
58-
if args.verbose:
59-
print("Results:", len(result["results"]))
60-
reports = create_reports(result, devices)
61-
for device in reports:
62-
if "privateKeyInt" in device:
63-
del device["privateKeyInt"]
64-
send_reports(args.endpoint, reports, headers=args.headers)
65-
if args.verbose:
66-
print(reports)
58+
device["privateKeyNumeric"] = bytes_to_int(privateKeyBytes)
59+
publicHashBase64 = b64_ascii(get_hashed_public_key(privateKeyBytes))
60+
device_mapping[publicHashBase64] = device
61+
62+
apple_result = apple_fetch(command_args.key, list(device_mapping.keys()))
63+
if command_args.verbose:
64+
print("Results:", len(apple_result["results"]))
65+
66+
report_list = create_reports(apple_result, device_mapping)
67+
for report in report_list:
68+
if "privateKeyNumeric" in report:
69+
del report["privateKeyNumeric"]
70+
71+
send_reports(command_args.endpoint, report_list, headers=command_args.headers)
72+
if command_args.verbose:
73+
print(report_list)

report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def create_reports(response_json, devices):
1515
data = b64decode(result["payload"])
1616
timestamp = bytes_to_int(data[0:4]) + EPOCH_DIFF
1717
device = devices[result["id"]]
18-
private_key = device["privateKeyInt"]
18+
private_key = device["privateKeyNumeric"]
1919
report = decode_tag(get_result(private_key, data))
2020
report["timestamp"] = timestamp
2121
report["datePublished"] = result["datePublished"]

0 commit comments

Comments
 (0)