import re
import click


def gid_for_sheets_url(url):
    """extract just the gid (worksheet id) from a google docs url"""
    m = re.search('.*#gid=(\\d+)$', url)
    if m:
        return m.group(1)
    else:
        click.echo('Invalid Google Sheets URL')
        raise click.Abort()