Skip to content

Commit 3e135ee

Browse files
committed
apple chunks
1 parent 8d0e6a0 commit 3e135ee

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

apple_fetch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
Fetch from Apple's acsnservice
33
"""
44

5-
from requests import post
5+
from requests import Session
66
from haystack import get_headers
77
from helpers import status_code_success
88
from date import unix_epoch, date_milliseconds
99

10+
requestSession = Session()
11+
1012

1113
def acsnservice_fetch(decryption_key, ids, startdate, enddate):
1214
"""Fetch from Apple's acsnservice"""
@@ -19,7 +21,7 @@ def acsnservice_fetch(decryption_key, ids, startdate, enddate):
1921
}
2022
]
2123
}
22-
return post(
24+
return requestSession.post(
2325
"https://gateway.icloud.com/acsnservice/fetch",
2426
headers=get_headers(decryption_key),
2527
json=data,

main.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
from argparse import ArgumentParser
99
import json
10+
from time import sleep
1011
from api import fetch_devices, send_reports
1112
from cryptic import b64_ascii, get_hashed_public_key, bytes_to_int
1213
from apple_fetch import apple_fetch
14+
from helpers import chunks
1315
from report import create_reports
1416

1517

@@ -59,15 +61,15 @@ def get_args():
5961
publicHashBase64 = b64_ascii(get_hashed_public_key(privateKeyBytes))
6062
device_mapping[publicHashBase64] = device
6163

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)
64+
for devices_chunk in chunks(device_mapping, 10):
65+
apple_result = apple_fetch(command_args.key, list(devices_chunk.keys()))
66+
if command_args.verbose:
67+
print("Results:", len(apple_result["results"]))
68+
report_list = create_reports(apple_result, device_mapping)
69+
for report in report_list:
70+
if "privateKeyNumeric" in report:
71+
del report["privateKeyNumeric"]
72+
send_reports(command_args.endpoint, report_list, headers=command_args.headers)
73+
if command_args.verbose:
74+
print(report_list)
75+
sleep(0.1)

0 commit comments

Comments
 (0)