in scripts/bulk-update-status.py [0:0]
def get_filtered_commission_records(timestamp, status, headers, commission_list_url, title=None) -> list:
print("TIMESTAMP: ", timestamp)
request_body = {
"match": "W_CONTAINS",
"completionDateBefore": timestamp
}
if status:
request_body["status"] = status
if title:
request_body["title"] = title
json_body = json.dumps(request_body)
records = []
try:
json_content = api_put_request(commission_list_url, headers, json_body)
total_records = json_content["count"]
total_pages = (total_records + MAX_RECORDS_PER_PAGE - 1) // MAX_RECORDS_PER_PAGE
start_at = 0
for page in range(1, total_pages + 1):
print(f"loading page: {page}")
response = api_put_request(
f"{commission_list_url}?startAt={start_at}&length={MAX_RECORDS_PER_PAGE}",
headers,
json_body,
)
json_content = response
logging.debug(f"page: {page}, records: {json_content['result']}")
if status is None:
records.extend([record for record in json_content["result"] if record["status"] not in ["Completed", "Killed"]])
else:
records.extend(json_content["result"])
start_at += MAX_RECORDS_PER_PAGE
except requests.exceptions.RequestException as e:
print(e)
raise Exception("An error occurred. Exiting script...")
# write records to file
unix_timestamp = str(time.time()).split(".")[0]
with open(f"commissions_before{timestamp}-{unix_timestamp}.json", "a") as f:
json.dump(records, f)
return records