Pythonで漢数字の和暦を変換

def kanji2int(s):

    ksuji = str.maketrans('一二三四五六七八九〇元', '12345678901')

    m = re.match("(\d)?(十)?(\d)?", s.translate(ksuji))
    t = m.groups()

    result = 0

    if t[1] == "十":
        result = int("".join([m.group(1) if m.group(1) else "1", m.group(3) if m.group(3) else "0"]))
    else:
        result =int(m.group(1))
    
    return result


def wareki2date(s):

    m = re.match("(昭和|平成|令和)(.+)年(.+)月(.+)日", s)

    year = kanji2int(m.group(2))
    month = kanji2int(m.group(3))
    day = kanji2int(m.group(4))

    if m.group(1) == "昭和":
        year += 1925
    elif m.group(1) == "平成":
        year += 1988
    elif m.group(1) == "令和":
        year += 2018
    
    result = datetime.date(year, month, day)

    return result