From 8c2ce60f77f39ea8eca32a012ce319c13dc27b59 Mon Sep 17 00:00:00 2001 From: Lars Beemster Date: Wed, 1 Nov 2023 09:54:28 +0100 Subject: [PATCH] fix single quoting ids list for issue #20 --- FindMy_client.py | 15 ++++++++++++--- request_reports.py | 12 ++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/FindMy_client.py b/FindMy_client.py index 6504e61..10f7a76 100755 --- a/FindMy_client.py +++ b/FindMy_client.py @@ -56,13 +56,22 @@ def decode_tag(data): names[hashed_adv] = name else: print("Couldn't find key pair in", keyfile) - - data = '{"search": [{%s"ids": %s}]}' % ('' if args.map else '"startDate": 0, ', list(ids.keys())) + unixEpoch = int(datetime.datetime.now().strftime('%s')) + startdate = unixEpoch - 60 * 60 * 24 * 7 + data = { + "search": [ + { + "startDate": startdate *1000, + "endDate": unixEpoch *1000, + "ids": list(ids.keys()) + } + ] + } sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect(('', 6176)) - sock.sendall(bytes(data + '\n', encoding='ascii')) + sock.sendall(bytes(json.dumps(data) + '\n', encoding='ascii')) response = b'' while True: rdata = sock.recv(1024) diff --git a/request_reports.py b/request_reports.py index caf50da..176e84e 100755 --- a/request_reports.py +++ b/request_reports.py @@ -170,11 +170,19 @@ def getCurrentTimes(): print("Couldn't find key pair in", keyfile) startdate = unixEpoch - 60 * 60 * args.hours - data = '{"search": [{"endDate": %d, "startDate": %d, "ids": %s}]}' % ((unixEpoch -978307200) *1000000, (startdate -978307200)*1000000, list(ids.keys())) + data = { + "search": [ + { + "startDate": startdate *1000, + "endDate": unixEpoch *1000, + "ids": list(ids.keys()) + } + ] + } # send out the whole thing import requests - response = requests.post('https://gateway.icloud.com/acsnservice/fetch', headers=request_headers, data=data) + response = requests.post('https://gateway.icloud.com/acsnservice/fetch', headers=request_headers, json=data) print(response.status_code, response.reason) res = response.json()['results'] print('%d reports received.' % len(res))