Generate a Remind command from the given vevent

def to_remind(self, vevent, label=None, priority=None, tags=None, tail=None,
                  sep=" ", postdate=None, posttime=None):
        """Generate a Remind command from the given vevent"""
        remind = ['REM']

        trigdates = None
        if hasattr(vevent, 'rrule'):
            trigdates = Remind._parse_rruleset(vevent.rruleset)

        dtstart = vevent.dtstart.value
        # If we don't get timezone information, handle it as a naive datetime.
        # See https://github.com/jspricke/python-remind/issues/2 for reference.
        if isinstance(dtstart, datetime) and dtstart.tzinfo:
            dtstart = dtstart.astimezone(self._localtz)

        dtend = None
        if hasattr(vevent, 'dtend'):
            dtend = vevent.dtend.value
        if isinstance(dtend, datetime) and dtend.tzinfo:
            dtend = dtend.astimezone(self._localtz)

        if not hasattr(vevent, 'rdate') and not isinstance(trigdates, str):
            remind.append(dtstart.strftime('%b %d %Y').replace(' 0', ' '))

        if postdate:
            remind.append(postdate)

        if priority:
            remind.append('PRIORITY %s' % priority)

        if isinstance(trigdates, list):
            remind.extend(trigdates)

        duration = Remind._event_duration(vevent)

        if type(dtstart) is date and duration.days > 1:
            remind.append('*1')
            if dtend is not None:
                dtend -= timedelta(days=1)
                remind.append(dtend.strftime('UNTIL %b %d %Y').replace(' 0', ' '))

        if isinstance(dtstart, datetime):
            remind.append(dtstart.strftime('AT %H:%M').replace(' 0', ' '))

            if posttime:
                remind.append(posttime)

            if duration.total_seconds() > 0:
                remind.append('DURATION %d:%02d' % divmod(duration.total_seconds() / 60, 60))

        if hasattr(vevent, 'rdate'):
            remind.append(Remind._parse_rdate(vevent.rdate.value))
        elif isinstance(trigdates, str):
            remind.append(trigdates)

        if hasattr(vevent, 'class'):
            remind.append('TAG %s' % Remind._abbr_tag(vevent.getChildValue('class')))

        if tags:
            remind.extend(['TAG %s' % Remind._abbr_tag(tag) for tag in tags])

        if hasattr(vevent, 'categories_list'):
            for categories in vevent.categories_list:
                for category in categories.value:
                    remind.append('TAG %s' % Remind._abbr_tag(category))

        remind.append(Remind._gen_msg(vevent, label, tail, sep))

        return ' '.join(remind) + '\n'