I'm collecting weather data and trying to create a list that has the latest (temperature) value by minute.
I want to add them to a list, and if the list does not contains the "minute index" it should at it as a new element in the list. So the list always keeps the latest temperature value per minute:
def AddValue(arr, value):
timestamp = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M")
for v in arr['values']:
try:
e = v[timestamp] # will trigger the try/catch if not there
v[timestamp] = value
except KeyError:
v.append({ timestamp: value })
history = [
{ 'values': [ {'2017-12-22 10:20': 1}, {'2017-12-22 10:21': 2}, {'2017-12-22 10:22': 3} ] },
]
AddValue(history, 99)
However, I'm getting
AttributeError: 'dict' object has no attribute 'append'**