import re


def read_timespan(ts):
    """ Read sleep-like timespan, return it as seconds """
    if not re.fullmatch("((\d+)([dwms]?))+", ts):
        raise ValueError("Invalid timespan: '{}'".format(ts))

    seconds = 0
    for amount, multiplier in re.findall("(\d+)([dwms]?)", ts):
        if multiplier == "w":
            seconds += int(amount) * 60 * 60 * 24 * 7
        elif multiplier == "d":
            seconds += int(amount) * 60 * 60 * 24
        elif multiplier == "h":
            seconds += int(amount) * 60 * 60
        elif multiplier == "m":
            seconds += int(amount) * 60
        else:
            seconds += int(amount)
    return seconds