The code I use below is a function that allows me to get data from an API:
def get_evt(adresse, id_machine, bucket_size, token, data):
TO_DATE = datetime.strptime("25/11/2019, 22:00:00", "%d/%m/%Y, %H:%M:%S").timetuple()
param = {
"from": int((mktime(TO_DATE) - (60 * 60 * HOUR_DIFF)) * 1000),
"to": int(mktime(TO_DATE) * 1000),
"bucketSize": bucket_size,
"queries": [
{
"signal": data,
"aggregationFunction": "raw",
"groupBy": {
"type": "machine",
"id": id_machine
}
}
]
}
liste = []
resp = requests.post(adresse, headers=token, json=param)
if resp.status_code != 200:
# This means something went wrong.
print('ERROR ', resp.status_code, ': ', resp.json()["message"])
print(resp.json()["message"])
else:
signalsData = resp.json()
for param in range(len(signalsData)):
values = signalsData[param]['timeseries']
print(values)
for value in values:
timestamp = int(value['time']/bucket_size)
valeur = value['value']
return timestamp, valeur
However in this code this for loop only loops once:
for value in values:
timestamp = int(value['time']/bucket_size)
valeur = value['value']
return timestamp, valeur
What I would like to achieve is to somehow get the first and last value of the list "values" but I don't understand why the loop only works once even though values contains multiple values.