How to check if the Market is open today or not

This checks if market FNO segment is open -

from nsepythonserver import*

def is_market_open(segment = "FO"): #COM,CD,CB,CMOT,COM,FO,IRD,MF,NDM,NTRP,SLBS
    
    holiday_json = nse_holidays()[segment]

    # Get today's date in the format 'dd-Mon-yyyy'
    today_date = datetime.date.today().strftime('%d-%b-%Y')

    # Check if today's date is in the holiday_json
    for holiday in holiday_json:
        if holiday['tradingDate'] != today_date:
            print("FNO Market is open today. Have a Nice Trade!")
            return True
        if holiday['tradingDate'] == today_date:
            print(f"Market is closed today because of {holiday['description']}")
            return False

is_market_open()

Output -

True

It is because https://unofficed.com/nse-python/documentation/special/#the-market-status-api this API does not work all the time and throws an error.