Code: Alles auswählen
weekdaymatch = re.match('(?P<weekday>on (?P<dayofweek>(montag?|dienstag?|mittwoch?|donnerstag?|freitag?|samstag?|sontag?)) at ((?P<weekdayhour>([0-9]{1,2}):?\s*([0-9]{2})?\s*)(?P<weekdayampm>(am|pm))?|noon|midnight)(\s|$))', answer, re.IGNORECASE)
if weekdaymatch is not None:
#print "weekdayfound"
timetype = "Hour"
dayofweek = weekdaymatch.group('dayofweek')
parsehour = weekdaymatch.group('weekdayhour')
hour = weekdaymatch.group('weekdayhour')
timehint = weekdaymatch.group('weekdayampm')
#print timehint
#print len(hour)
#print len(hour)
if dayofweek == "montag":
dayofweek = 1
if dayofweek == "dienstag":
dayofweek = 2
if dayofweek == "mittwoch":
dayofweek = 3
if dayofweek == "donnerstag":
dayofweek = 4
if dayofweek == "freitag":
dayofweek = 5
if dayofweek == "samstag":
dayofweek = 6
if dayofweek == "sontag":
dayofweek = 7
if len(str(hour)) < 4:
for pmhints in pmWords:
if pmhints in timehint:
#print "using PM"
#print hour
if int(hour) == 12:
correctTime = x.replace(hour=int(hour), minute=0, second=0, microsecond=0)
if int(hour) != 12:
hour = int(hour) + 12
correctTime = x.replace(hour=hour, minute=0, second=0, microsecond=0)
for amhints in amWords:
if amhints in timehint:
#print "using AM"
if int(hour) == 12:
correctTime = x.replace(hour=23, minute=59, second=0, microsecond=0)
if int(hour) != 12:
correctTime = x.replace(hour=int(hour), minute=0, second=0, microsecond=0)
if len(str(hour)) > 3:
if len(str(hour)) == 4:
hour = parsehour[0]
minutes = parsehour[1:3]
if len(str(hour)) == 5:
hour = parsehour[0:2]
minutes = parsehour[2:4]
#print hour
#print minutes
x = datetime.now(tz)
for pmhints in pmWords:
if pmhints in timehint:
#print "using PM"
if int(hour) == 12:
correctTime = x.replace(hour=int(hour), minute=int(minutes), second=0, microsecond=0)
if int(hour) != 12:
hour = int(hour) + 12
correctTime = x.replace(hour=int(hour), minute=int(minutes), second=0, microsecond=0)
for amhints in amWords:
if amhints in timehint:
#print "using AM"
if int(hour) == 12:
correctTime = x.replace(hour=23, minute=59, second=0, microsecond=0)
if int(hour) != 12:
correctTime = x.replace(hour=int(hour), minute=int(minutes), second=0, microsecond=0)
#print x.isoweekday()
#print dayofweek
if x.isoweekday() < dayofweek:
difference = dayofweek - x.isoweekday()
correctTime = correctTime + timedelta(days=difference)
if x.isoweekday() > dayofweek:
difference = dayofweek - x.isoweekday() + 7
correctTime = correctTime + timedelta(days=difference)