I currently have the following where the AllergiesList can be one or more dicts
.
{
"AllergiesList": [
{
"Date": "2021-09-03T00:00:00",
"Description": "string",
"Source": "string",
"Severity": "string",
"Reaction": "string",
"TypeCode": "string",
"Notes": "string",
"Notes1": "string",
"TenancyDescription": "string"
}
],
"TotalItemCount": 0
}
My question is how would I format the Date
key within all dictionaries to be in a specific format e.g. d/m/Y
I currently have the following to remove dicts
that are more than X months old
def is_recent(entry,amount):
limit_time = pd.Timestamp.today() - relativedelta.relativedelta(months=amount)
return pd.to_datetime(entry["Date"]) > limit_time
Used as follows:
allergies = session["allergies"] # This is the same as the code snippet above i.e. a list of dictionaries
session["allergies"] = [entry for entry in allergies["AllergiesList"] if is_recent(entry,6)]
Would I need to do another def()
or can my current one be amended to do what's needed?