直接上代码
def Datajudge(weeks,hourMin):
print("hourMin ",hourMin[0],hourMin[1],weeks)
flag = 1
while flag:
curretTime= time.localtime() #获取本地的时间
newweeks = datetime.now().isoweekday() # 1-7表示星期一到星期天
#print(curretTime)
fmt = “%H,%M”
now = time.strftime(fmt, curretTime)
now = now.split(’,’)
hour = now[0]
minute = now[1]
if hour == hourMin[0] and minute == hourMin[1] and (weeks==newweeks or weeks==0):
print('时间到了!!!!!!!!!!!!!!!!!!!')
flag=0
def WeekData(mytime,hourMin):
weekArr=[“星期一”,“星期二”,“星期三”,“星期四”,“星期五”,“星期六”,“星期天”,“星期日”]
weeks=11
if (re.findall(’.明天.’, mytime) != []):
print(“明天”)
weeks=datetime.now().isoweekday() #1-7表示星期一到星期天
weeks=weeks+1
Datajudge(weeks,hourMin)
elif (re.findall(’.每.’, mytime) != [] or re.findall(’.个.’, mytime) != []):
print(“每”)
weeks=0
Datajudge(weeks, hourMin)
elif (re.findall(’.星期.’, mytime) != []):
print(“星期”)
i=0
for weekAr in weekArr:
i=i+1
newWeek = ‘.’ + weekAr + '.’
if(re.findall(newWeek, mytime) != []):
if(i7):
i=7
weeks=i
break
if(weeks11):
print(“不知道星期几,请重新输入”)
Datajudge(weeks, hourMin)
else:
print(“早上”)
weeks = datetime.now().isoweekday()
Datajudge(weeks, hourMin)
def MorNoo(mytime):
hourMin = re.findall(’\d+’,mytime) #获取字符串中数字,时,分
if(re.findall(’.下午.’,mytime)!=[] or re.findall(’.晚上.’,mytime)!=[]): #下午或者晚上
print(“下午”)
if (1 <= int(hourMin[0]) and int(hourMin[0]) <= 12):
hourMin[0] =str(int(hourMin[0]) + 12)
WeekData(mytime, hourMin)
else:
WeekData(mytime, hourMin)
while True:
mytime=“20点47分”
mytime = input(“请输入时:”)
MorNoo(mytime)