I have strings looks like JSONs. if I print the type of them the output will be str.
{"date": "2022-09-14 15:22:53.084456"}
{"date": "2022-09-14 11:37:33.753514"}
I did convert them into real JSONs. Using this:
i = json.loads(i)
Now print(i) will output this:
{'date': '2022-09-14 11:37:33.753514'}
And print(type(i)) will output this:
<class 'dict'>
And print(type(i['date'])) will output this:
<class 'str'>
Now convert it to real date, and append the dates to a list dates:
date = datetime.strptime(i['date'], '%Y-%m-%d %H:%M:%S.%f')
if date > datetime.now() - timedelta(hours=24):
dates = []
dates.append(date)
if len(dates) > 0:
print(len(dates))
Output:
1
[datetime.datetime(2022, 9, 14, 10, 56, 36, 284933)]
1
[datetime.datetime(2022, 9, 14, 11, 37, 33, 753514)]
The problem here I'm appending them to a list! But instead of adding all the dates into one list, it's creating a list for each date.
Wanted result:
print(len(dates))
2