def _extract_parts (text):

    # Examples:
    # remind me once monday at 4pm, Help!
    # remind me once two weeks from now, Help!
    #
    # remind me every 5 minutes, Help!
    # remind me every 1 day, Help!
    #
    # remind show
    # remind stop #1

    # With the above examples, we can say that the
    # format should follow the following:
    #
    # [script init] [set / show /stop / help] [once/every] [time]: [message]

    parts = {

        'recipient': None,
        'action': 'set',
        'recurrence': 'once',
        'time': None,
        'parsed_time': None,
        'message': None,
        'error': False,
        'error_message': None
    }

    # Check the action_recipient
    action_recipient = text.split(' ')[0].strip()

    # Ensure that the action is something we understand
    if action_recipient not in ['set', 'show', 'stop', 'help']:
        parts['error'] = True
        parts['error_message'] = 'Unknown command: {c}'.format(
            c = action_recipient
        )

        return parts

    # We are happy with the action. show and stop
    # actions dont care about the rest
    if action_recipient in ['show', 'stop', 'help']:
        parts['action'] = action_recipient
        return parts

    # Set the recipient and remove it from the text
    text = text.replace(action_recipient, '', 1).strip()
    parts['recipient'] = action_recipient

    # Next part is to check the recurrence.
    recurrence = text.split(' ')[0].strip()

    # Check that the recurrence is valid
    if recurrence not in ['once', 'every']:
        parts['error'] = True
        parts['error_message'] = 'Unknown recurrence: {r}'.format(
            r = recurrence
        )

        return parts

    # Set the recurrence and remove it from the text
    # only of it is set to 'once'
    text = text.replace('once', '', 1).strip()
    parts['recurrence'] = recurrence

    # Next, we parse the time. For this we should be
    # able to split by ,
    if len(text.split(',', 1)) != 2:
        parts['error'] = True
        parts['error_message'] = 'Time and message should be seperated by a comma ( , ) character'

        return parts

    # Set the time and the message
    time = text.split(',', 1)[0].strip()
    message = text.split(',', 1)[1].strip()

    # Resolve the human time to something we can work
    # with
    r = RecurringEvent()
    parsed_time = r.parse(time)

    # If the time parsing failed, oh well.
    if parsed_time is None:
        parts['error'] = True
        parts['error_message'] = 'Unable to parse time: {t}'.format(
            t = time
        )

        return parts

    # Set the time and parsed time, as well as the message
    # that should be used
    parts['time'] = time
    parts['parsed_time'] = parsed_time
    parts['message'] = message

    return parts
Extract Parts
dataset/ETHPy150Open leonjza/hogar/hogar/Plugins/Reminders/main.py/_extract_parts