-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.py
More file actions
47 lines (39 loc) · 1.47 KB
/
script2.py
File metadata and controls
47 lines (39 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
import json
# Define the API endpoint
api_endpoint = "http://localhost:8080/api/v1/play/round"
# Define your session ID and API ID
session_id = "0353f4cf-ddcb-496b-bdb9-1b41e05c8209"
api_key = "7bcd6334-bc2e-4cbf-b9d4-61cb9e868869"
# Load movements data from file
with open('movements13.txt', 'r') as file:
movements_data = json.load(file)
# Iterate over each day from 0 to 42
for day in range(43):
# Extract movements for the current day
day_movements = next((item['movements'] for item in movements_data if item['day'] == day), [])
# Prepare the data to be sent in the POST request
data = {
"day": day,
"movements": day_movements
}
# Define headers including session ID and API ID
headers = {
"SESSION-ID": session_id,
"API-KEY": api_key
}
# Make the POST request
response = requests.post(api_endpoint, json=data, headers=headers)
# Check the response status
if response.status_code == 200:
print(f"Successfully posted data for day {day}")
# Print only the totalKpis from the response data
try:
response_data = response.json()
total_kpis = response_data.get("totalKpis", {})
print("Total KPIs:", total_kpis)
except ValueError:
print("Response is not in JSON format")
else:
print(f"Failed to post data for day {day}: {response.status_code}")
print("Response content:", response.text)