With the following code:
class Calendar_Data(Resource):
def get(self):
result = []
details_array = []
# Times are converted to seconds
for day in life.days:
for span in day.spans:
if type(span.place) is str:
details = {
'name': span.place,
'date': 0,
'value': (span.length() * 60),
}
details_array.append(details)
data = {
'date': datetime.datetime.strptime(day.date, '%Y_%m_%d').strftime('%Y-%m-%d'),
'total': (day.somewhere() * 60),
'details': details_array
}
result.append(data)
return result
What I'm trying to do is for each day that is present in a list of days, get the corresponding spans for that day, and fill the array with the details. Then pass that details to the data array in order to have it for each day of that list of days.
The problem here is when I use these nested loops above, it fills me the details with the all the spans from all days, instead of each single day.
I don't thin using a zip in this case would work. Maybe some list comprehension but I still did not understand that fully.
Example input:
--2016_01_15
@UTC
0000-0915: home
0924-0930: seixalinho station
1000-1008: cais do sodre station
1009-1024: cais do sodre station->saldanha station
1025-1027: saldanha station
1030-1743: INESC
1746-1750: saldanha station
1751-1815: saldanha station->cais do sodre station
1815-1834: cais do sodre station {Waiting for the boat trip back. The boat was late}
1920-2359: home [dinner]
--2016_01_16
0000-2136: home
2147-2200: fabio's house
2237-2258: bar [drinks]
For the sixteenth of january the details array is supposed to have 3 items, but each day constantly shows all of the items of all days.