import os
import re


def subdirs(path):
    return [d for d in os.listdir(path) if os.path.isdir(path / d)]


def files(path, extension=None):
    return [f for f in os.listdir(path) if os.path.isfile(path / f) and (extension is None or f.endswith(extension))]


def contains_any(string, keywords):
    for keyword in keywords:
        if re.search(fr'\b{keyword.lower()}\b', string.lower()):
            return True
    return False


def first_day_of_month(date):
    return date[:-2] + '01'


def last_day_of_month(date):
    year, month, _ = date.split('-')
    last_day = {
        '01': '31',
        '02': '29' if int(year) % 400 == 0 or (int(year) % 4 == 0 and int(year) % 100 != 0) else '28',
        '03': '31',
        '04': '30',
        '05': '31',
        '06': '30',
        '07': '31',
        '08': '31',
        '09': '30',
        '10': '31',
        '11': '30',
        '12': '31'
    }[month]
    return date[:-2] + last_day


