Apr-05-2020, 12:11 PM
I have a SQLite database that I've selected into an array cursor where each row has a date element. I've already sorted cursor by date.
I effectively have something like:
In the end, it should have:
And so on.
I'm having trouble how to actually structure the for loops to end the "day" and begin another "day", and the same for a "month".
For now, all I have is:
I effectively have something like:
cursor = [ [data1, "date", date2, date3], [data1, "date", date2, date3], [data1, "date", date2, date3], [data1, "date", date2, date3] ]Using two for loops, I want to write a string for each row, group them together by day, and then group and write those days by month per year.
In the end, it should have:
Quote:-> 2020-02.txt
2020-02-01
data
data
2020-02-02
data
2020-02-05
data
-> 2020-03.txt
2020-03-02
data
2020-03-05
data
And so on.
I'm having trouble how to actually structure the for loops to end the "day" and begin another "day", and the same for a "month".
For now, all I have is:
date_test = date.fromisoformat(cursor[0][2]) for idx, val in enumerate(sorted(cursor, key=lambda row: row[2])): # Check if the year is different if date_test.strftime("%Y") != date.fromisoformat(val[2]).strftime("%Y"): # Check if month is different... pass