def convert_rrule(rrule):
    """Converts icalendar rrule to dateutil rrule."""
    args = {}

    # TODO: rrule['freq'] is a list, but I'm unclear as to why.
    freq = FREQ_MAP[rrule['freq'][0]]

    keys = ['wkst', 'until', 'bysetpos', 'interval',
            'bymonth', 'bymonthday', 'byyearday', 'byweekno',
            'byhour', 'byminute', 'bysecond']

    def tweak(rrule, key):
        value = rrule.get(key)
        if isinstance(value, list):
            return value[0]
        return value

    args = dict((key, tweak(rrule, key)) for key in keys if rrule.get(key))

    byweekday = rrule.get('byweekday')
    if byweekday:
        byweekday = byweekday[0]
        count, day = int(byweekday[0]), byweekday[1:]
        args['byweekday'] = WEEKDAY_MAP[day](count)

    return freq, args
Converts icalendar rrule to dateutil rrule.