I need to define a function to get a [list] of str values of time from "M" minutes before the current time, up to the current time (including current time), and then check whether any of the values match the time value in the Time column of a given CSV file.
I thought of the idea for a for loop but could not figure out how to add and append the list for M no. of times (Quality of an Absolute Beginner). So, I adjusted with the following code which only supports M = 1 :
def Time_Check_Min(M= 1):
#Check the current system time
timestr = datetime.now()
Check_TIMEnow = timestr.strftime("%H:%M")
#Add 'M' min to Current Time
Ahead_Time = (timestr + timedelta(minutes=M))
Check_TIME = Ahead_Time.strftime("%H:%M")
#Check if the current time is mentioned in the Dataframe
if Check_TIME in df_.Time.values or Check_TIMEnow in df_.Time.values:
return True
else:
return False
I require the output as a list in ('%H:%M') format so as to then check if any of them is present in the CSV. For Example, Taking the current system time to be '16:50' and M = 3 , then the list should contain 4 elements, like :
['16:47', '16:48', '16:49', '16:50']
Also, I thought of using the between time method since I am using pandas. But again, I do not know if this would really help.
Do I need to change my approach? If Yes, then which would be the best way to do so... and if not, HOW to get that damn list?
!! Thanks for your Time for these Time_Values !!