def next_occurrence(reminder):
now = datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)<EOL>now_dow = now.weekday()<EOL>start_dow = now_dow + <NUM_LIT:1><EOL>end_dow = start_dow + <NUM_LIT:7><EOL>dow_iter = imap(lambda x: x % <NUM_LIT:7>, xrange(start_dow, end_dow))<EOL>dow_iter = ifilter(lambda x: x in reminder['<STR_LIT>'], dow_iter)<EOL>try:<EOL><INDENT>next_dow = next(dow_iter)<EOL><DEDENT>except StopIteration:  <EOL><INDENT>logger.exception("<STR_LIT>")<EOL>_scheduled.discard(reminder['<STR_LIT>'])<EOL>return<EOL><DEDENT>day_delta = next_dow<EOL>if next_dow <= now_dow:<EOL><INDENT>day_delta += <NUM_LIT:7><EOL><DEDENT>day_delta -= now_dow<EOL>return reminder['<STR_LIT>'] + datetime.timedelta(days=day_delta), day_delta<EOL>
Calculate the next occurrence of a repeatable reminder