嗨,我是一个初学者,我正在尝试运行一个while循环,该循环在某个时间发送通知,然后在发送通知后停止运行,但是每次我运行该程序时while循环都没有结束。有人知道为什么吗?这是代码:
def notify():
with open('task.json') as file:
data = json.load(file)
tday = datetime.date.today()
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
for task in data['Reminder']:
for day in days:
if day == task['Date']:
dateIndex = days.index(day)
if dateIndex == tday.weekday():
comment = f"You are suppose to work on {task['Task']} today"
Task.notification(comment)
print(f"You are suppose to work on your {task['Task']} on {task['Date']}" )
if __name__ == '__main__':
while True:
now = datetime.datetime.now()
timeAM = f'{now.hour}:{now.minute} AM'
timePM = f'{now.hour - 12}:{now.minute} PM'
with open('task.json') as file:
data = json.load(file)
for task in data['Reminder']:
if timeAM == task['Time'] or timePM == task['Time']:
notify()
break
else:
pass