<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def at_reminder(client, channel, nick, args):
 """ Schedule a reminder to occur at a specific time. The given time can optionally be specified to occur at a specific timezone, but will default to the value of settings.TIMEZONE if none is specified. Times should be on a 24-hour clock. These types of reminders are repeatable, should the last two words of the message be of the form "repeat <days_of_week>" where days_of_week is a single string consisting of any of the following days: M, Tu, W, Th, F, Sa, Su. For example, 'repeat MWF' will repeat a reminder at the same time every Monday, Wednesday, and Friday. A full example of how one would use this: <sduncan> helga at 13:00 EST standup time repeat MTuWThF This will create a reminder "standup time" to occur at 1:00PM Eastern every weekday. Optionally, a specific channel can be specified to receive the reminder message. This is useful if creating several reminders via a private message. To use this, specify "on <channel>" between the time amount and the message: <sduncan> helga at 13:00 EST on #bots standup time repeat MTuWThF <sduncan> helga at 13:00 EST on bots standup time repeat MTuWThF Note that the '#' char for specifying the channel is entirely optional. """

    global _scheduled

    now = datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)

    # Parse the time it should go off, and the minute offset of the day
    hh, mm = map(int, args[0].split(':'))

    # Strip time from args
    args = args[1:]

    # Default timezone
    timezone = pytz.timezone(getattr(settings, 'TIMEZONE', 'US/Eastern'))

    try:
        # If there was a timezone passed in
        timezone = pytz.timezone(args[0])
    except pytz.UnknownTimeZoneError:
        pass
    else:
        # If so, remove it from args
        args = args[1:]

    local_now = now.astimezone(timezone)
    local_next = local_now.replace(hour=hh, minute=mm)

    if local_next <= local_now:
        local_next += datetime.timedelta(days=1)

    reminder = {
        'when': local_next.astimezone(pytz.UTC),
        'channel': channel,
        'message': ' '.join(args),
        'creator': nick,
    }

    # Check for 'repeat' arg
    try:
        repeat = args[-2] == 'repeat'
    except IndexError:
        repeat = False

    if repeat:
        # If repeating, strip off the last two for the message
        sched = args[-1]
        reminder['message'] = ' '.join(args[:-2])
        repeat_days = sorted([v for k, v in days_of_week.iteritems() if k in sched])

        if not repeat_days:
            return u"I didn't understand '{0}'. You must use any of M,Tu,W,Th,F,Sa,Su. Ex: MWF".format(sched)

        reminder['repeat'] = repeat_days

        for attempt in xrange(7):
            if reminder['when'].weekday() in repeat_days:
                break
            reminder['when'] += datetime.timedelta(days=1)

    # Handle ability to specify the channel
    if reminder['message'].startswith('on'):
        parts = reminder['message'].split(' ')
        chan = parts[1]
        reminder['message'] = ' '.join(parts[2:])

        # Make sure channel is formatted correctly
        if not chan.startswith('#'):
            chan = '#{0}'.format(chan)
        reminder['channel'] = chan

    id = db.reminders.insert(reminder)

    diff = reminder['when'] - now
    delay = (diff.days * 24 * 3600) + diff.seconds

    _scheduled.add(id)
    reactor.callLater(delay, _do_reminder, id, client)
    return u'Reminder set for {0} from now'.format(readable_time_delta(delay))