<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def account_groups_and_extra_data(account, resource, refresh_timedelta=None):
 """Fetch account groups and extra data from resource if necessary."""

    updated = datetime.utcnow()
    modified_since = updated
    if refresh_timedelta is not None:
        modified_since += refresh_timedelta
    modified_since = modified_since.isoformat()
    last_update = account.extra_data.get('updated', modified_since)

    if last_update > modified_since:
        return account.extra_data.get('groups', [])

    groups = fetch_groups(resource['Group'])
    extra_data = current_app.config.get(
        'OAUTHCLIENT_CERN_EXTRA_DATA_SERIALIZER',
        fetch_extra_data
    )(resource)

    account.extra_data.update(
        groups=groups,
        updated=updated.isoformat(),
        **extra_data
    )
    return groups