def parse_timespan(timespan):
    tokens = tokenize(timespan)
    if tokens and isinstance(tokens[0], numbers.Number):
        # If the input contains only a number, it's assumed to be the number of seconds.
        if len(tokens) == 1:
            return float(tokens[0])
        # Otherwise we expect to find two tokens: A number and a unit.
        if len(tokens) == 2 and is_string(tokens[1]):
            normalized_unit = tokens[1].lower()
            for unit in time_units:
                if normalized_unit in (unit['singular'], unit['plural'], unit['abbreviation']):
                    return float(tokens[0]) * unit['divider']
    # We failed to parse the timespan specification.
    msg = "Failed to parse timespan! (input %r was tokenized as %r)"
    raise InvalidTimespan(msg % (timespan, tokens))
Parse a "human friendly" timespan into the number of seconds.
dataset/ETHPy150Open xolox/python-humanfriendly/humanfriendly/__init__.py/parse_timespan